Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 460346330DF for ; Thu, 25 Mar 2010 17:26:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 73166-06 for ; Thu, 25 Mar 2010 20:25:57 +0000 (UTC) X-Greylist: delayed 00:06:11.788559 by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id D11CB632FB0 for ; Thu, 25 Mar 2010 17:25:57 -0300 (ADT) Received: by vws8 with SMTP id 8so989681vws.19 for ; Thu, 25 Mar 2010 13:25:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.93.79 with SMTP id u15mr5748916vcm.81.1269548384650; Thu, 25 Mar 2010 13:19:44 -0700 (PDT) Date: Thu, 25 Mar 2010 13:19:44 -0700 Message-ID: <7a8b7ba31003251319y391cef47sff3c5ee3bba5eb4c@mail.gmail.com> Subject: Problems with semicolon trying to create a trigger function via jdbc From: Collin Peters To: pgsql-jdbc@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.185 tagged_above=-10 required=5 tests=BAYES_40=-0.185 X-Spam-Level: X-Archive-Number: 201003/57 X-Sequence-Number: 20397 Hi all, I have some framework code that needs to dynamically generate a function.=A0 There seems to be a problem where the SQL gets truncated at the first semicolon encountered in the function.=A0 I have tried this with a very simple function and duplicated it. The test trigger function is as follows: CREATE OR REPLACE FUNCTION test() =A0 RETURNS trigger AS $BODY$ DECLARE =A0=A0=A0 foo integer; BEGIN =A0=A0=A0 foo =3D 4; =A0=A0=A0 RAISE NOTICE 'Foo: %', foo; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE COST 100; ALTER FUNCTION test() OWNER TO mcrtdbms; The simple test code is: String sql =3D "CREATE OR REPLACE FUNCTION history.history_insert_trigger()=A0=A0=A0=A0 RETURNS trigger AS=A0=A0 $BODY= $ DECLARE=A0=A0 foo integer;=A0=A0 BEGIN=A0=A0=A0 foo =3D 4; RAISE NOTICE 'Fo= o: %', foo; =A0=A0=A0=A0 END;=A0=A0 $BODY$=A0=A0=A0=A0 LANGUAGE 'plpgsql' VOLATILE; "; =A0=A0=A0 =A0=A0=A0 DataSource ds =3D getDataSource(); =A0=A0=A0 =A0=A0=A0 try =A0=A0=A0 =A0=A0=A0 { =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Connection conn =3D ds.getConnection(); =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 conn.setAutoCommit(true); =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Statement st =3D conn.createStatement(); =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 st.executeUpdate(sql); =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 st.close(); =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 conn.close(); =A0=A0=A0 =A0=A0=A0 } =A0=A0=A0 =A0=A0=A0 catch (SQLException e) =A0=A0=A0 =A0=A0=A0 { =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 e.printStackTrace(); =A0=A0=A0 =A0=A0=A0 } When I try to run this via my webapp I get the error: org.postgresql.util.PSQLException: ERROR: unterminated dollar-quoted string at or near "$BODY$=A0=A0 DECLARE=A0=A0 foo integer" =A0=A0=A0 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(= QueryExecutorImpl.java:1591) =A0=A0=A0 at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryE= xecutorImpl.java:1340) =A0=A0=A0 at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutor= Impl.java:192) So it seems to be truncating the SQL at the first semicolon it encounters which, of course, borks the whole thing.=A0 What is even stranger in my quest to get this working is that the above code actually WORKS when I run it through a JUnit test!!!=A0 I have made no progress in trying to figure out what is different between the unit test and the running webapp.=A0 At first I though it was my ORM so I tried with the straight JDBC code used above and so eliminated that. Now I am trying to determine if the Postgres JDBC driver is at fault. Here is the rest of the details =A0* JDBC version 8.3-605 JDBC 3 * Postgres 8.3 * JUnit 4 * Application is built w/ Spring (but this manual query shouldn't be affected by taht) * When the above query is run through the webapp, it is initially triggered by a Quartz (scheduling api) trigger (which runs when the webapp starts) Any help at all would be appreciated!! I am about to give up and write a function which will do the job of creating the trigger for me!! Regards, Collin