I've created a sql dump file using pg_dump. This export file contains functions which contain $$ characters. No problem to import the file with psql -f < filename>.
If want to import the file with ant using the SQLExec task, I get an exception like:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$"
Is there a way to import a file containing $$?
In the postgres Log it seems that the SQLExec tasks converts $$ to $ which the causes the error.
ERROR: syntax error at or near "$" at character 87 STATEMENT: CREATE FUNCTION process_create_servicenumber() RETURNS trigger LANGUAGE plpgsql AS $ BEGIN IF (TG_OP = 'DELETE') THEN RETURN OLD
Here my method
protected void importNewDbFromDumpFile() {
final class SqlExecuter extends SQLExec {
public SqlExecuter() {
Project project = new Project();
project.init();
setProject(project);
setTaskType("sql");
setTaskName("sql");
}
}
try {
SqlExecuter executer = new SqlExecuter();
executer.setSrc(new File(dbDumpFileLocation));
executer.setClasspath(createClasspath());
executer.setEscapeProcessing(true);
executer.setDriver("org.postgresql.Driver");
executer.setUrl("jdbc:postgresql://localhost/test");
executer.setPassword("test");
executer.setUserid("manager");
executer.execute();
} catch (Exception e) {
log.info("Exception importing database ...", e);
}
}