I created a sql dump file using pg_dump. This export file contains functions that contain the characters $$. There is no problem importing a file with psql -f <file_name>.
If you want to import a file using ant using the SQLExec task, I get an exception, for example:
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 SQLExec tasks convert $$ to $, which causes an error.
ERROR: syntax error at or near $$ in character 87 STATEMENT: CREATE FUNCTION process_create_servicenumber () RETURNS trigger LANGUAGE plpgsql AS $ BEGIN IF (TG_OP = 'DELETE') THEN RETURN OLD
Here is 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); } }
java sql postgresql ant
markus Jul 29 2018-12-21T00: 00Z
source share