0

当我尝试使用EmbeddedPostgres创建 PROCEDURE 时遇到问题

休息一切正常,除了当我尝试创建程序时请在代码下方找到。

EmbeddedPostgres pg = EmbeddedPostgres.builder().start();
Statement dbSetup = pg.getDatabase("postgres", "postgres").getConnection().createStatement();
dbSetup.execute("create database portal;");
dbSetup.execute("CREATE USER testadmin WITH PASSWORD 'testadmin123' CREATEDB;");
dbSetup.execute("ALTER USER testadmin WITH SUPERUSER;");
dbSetup.execute("ALTER ROLE testadmin SUPERUSER;");

String procedure = "CREATE PROCEDURE insert_data(a integer, b integer)\n" +
                   "LANGUAGE SQL\n" +
                   "AS $$\n" +
                  "INSERT INTO tbl VALUES (a);\n" +
                  "INSERT INTO tbl VALUES (b);\n" +
                  "$$;";

ResultSet rsnew = pg.getDatabase("testadmin", "portal").getConnection().createStatement().executeQuery(procedure);

面对以下异常

org.postgresql.util.PSQLException: ERROR: syntax error at or near "PROCEDURE"
  Position: 8
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307)
    at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270)
    at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:224)
    at com.myproject.embeddedpostgres.TestPostgreSQL.main(TestPostgreSQL.java:62)

任何人都可以请帮忙。

4

0 回答 0