試圖運行PL/pgSQL的通過JDBC驅動程序(PostgreSQL相關9.4.1211.jre7.jar;使用ANT)我得到以下錯誤:在或接近 「$」PostgreSQL的JDBC執行PL/pgSQL的
語法錯誤:ERROR有沒有辦法通過設置JDBC屬性或更改PL/pgSQL的查詢來解決這個問題?
查詢:
DO $$
BEGIN
CREATE SEQUENCE id_sequence_SEQ OWNED BY id_sequence.id;
EXCEPTION WHEN duplicate_table
THEN
END
$$
LANGUAGE plpgsql;
錯誤:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$"
Position: 5
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2158)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:291)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:305)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:291)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:269)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:265)
你不能只是執行CREATE SEQUENCE本身,然後從Java端捕獲任何潛在的異常? –
這段代碼並沒有真正從Java調用。這是一個預安裝ANT任務。 – user1854959