org.postgresql.util.PSQLException: ERROR: unterminated dollar-quoted string at or near "$BODY$

StackOverflow https://stackoverflow.com/questions/18927948

  •  29-06-2022
  •  | 
  •  

質問

I am trying to use dbunit-express in my java project to create some tables and functions on postgress in Junit tests.

I use this driver :

<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.2-1003-jdbc4</version>

The java class...

@Rule 
public EmbeddedDbTesterRule testDb = new EmbeddedDbTesterRule(); // with this you don't neet to call onSetup

@Test
public void testIt() throws Exception {

    try {
        DatabaseCreator databaseCreator = new DatabaseCreator();
        databaseCreator.setDdlFile("HistoryTables.ddl");
        databaseCreator.doCreateDbSchemaFromDdl(testDb.getSqlConnection());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

But I get this error...

org.postgresql.util.PSQLException: ERROR: unterminated dollar-quoted string at or near "$BODY$

The function looks like this.

CREATE OR REPLACE FUNCTION product_history()
RETURNS trigger AS
$BODY$
BEGIN
INSERT INTO product_history (id, product_id, edit_ts, name, print_provider_id,     description)
    VALUES (nextval('product_history_sequence'), OLD.id, now(), OLD.name,     OLD.print_provider_id, OLD.description);
RETURN NULL;
END;
$BODY$
LANGUAGE plpgsql;

The create works fine in PGAdmin 1.14.3 and in DBVisualizer 9.0.8

役に立ちましたか?

解決

Is the create function code included in HistoryTables.ddl? If yes the error might be caused by a limitation of DatabaseCreator. It splits statements read from the ddl file at ; (see line 127 of the source code. The function is therefore splitted into multiple statements disturbing the syntax.

Try to move the function code into an extra file and send this file as one statement to your server.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top