pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JDBC escaped scalar functions fail when used in function definition
2+ messages / 2 participants
[nested] [flat]

* JDBC escaped scalar functions fail when used in function definition
@ 2016-03-10 23:10 Adam Rauch <adam@labkey.com>
  2016-03-11 01:05 ` Re: JDBC escaped scalar functions fail when used in function definition David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Adam Rauch @ 2016-03-10 23:10 UTC (permalink / raw)
  To: pgsql-jdbc

While testing postgresql-9.4.1208.jar with our system, code is now 
failing when it attempts to use {fn now()} in the body of a PostgreSQL 
CREATE FUNCTION statement. This worked fine on 1207 and all previous 
versions of the driver.

In other words, the code below succeeds on 1207 but fails on 1208 
(passing in server, port, database, username, and password as parameters):

    import java.sql.*;

    public class PGTest
    {
         public static void main(String[] args)throws SQLException
         {
             try (Connection conn = DriverManager.getConnection("jdbc:postgresql://" + args[0] +":" + args[1] +"/" + args[2], args[3], args[4]))
             {
                 try (PreparedStatement stmt = conn.prepareStatement(
                         "CREATE FUNCTION public.fn_now() RETURNS VOID AS $$\n" +
                                 " BEGIN\n" +
                                 " SELECT {fn now()};" +
                                 " END;\n" +
                                 "$$ LANGUAGE plpgsql;" +
                                 "DROP FUNCTION public.fn_now();")) {
                     stmt.execute();
                 }
             }
         }
    }

Bug? Intentional change in behavior? Thanks, Adam

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: JDBC escaped scalar functions fail when used in function definition
  2016-03-10 23:10 JDBC escaped scalar functions fail when used in function definition Adam Rauch <adam@labkey.com>
@ 2016-03-11 01:05 ` David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2016-03-11 01:05 UTC (permalink / raw)
  To: Adam Rauch <adam@labkey.com>; +Cc: pgsql-jdbc

On Thu, Mar 10, 2016 at 4:10 PM, Adam Rauch <adam@labkey.com> wrote:

> While testing postgresql-9.4.1208.jar with our system, code is now failing
> when it attempts to use {fn now()} in the body of a PostgreSQL CREATE
> FUNCTION statement. This worked fine on 1207 and all previous versions of
> the driver.
>
> In other words, the code below succeeds on 1207 but fails on 1208 (passing
> in server, port, database, username, and password as parameters):
>
> import java.sql.*;
> public class PGTest
> {
>     public static void main(String[] args) throws SQLException
>     {
>         try (Connection conn = DriverManager.getConnection("jdbc:postgresql://" + args[0] + ":" + args[1] + "/" + args[2], args[3], args[4]))
>         {
>             try (PreparedStatement stmt = conn.prepareStatement(
>                     "CREATE FUNCTION public.fn_now() RETURNS VOID AS $$\n" +
>                             "    BEGIN\n" +
>                             "        SELECT {fn now()};" +
>                             "    END;\n" +
>                             "$$ LANGUAGE plpgsql;" +
>                             "DROP FUNCTION public.fn_now();")) {
>                 stmt.execute();
>             }
>         }
>     }
> }
>
> Bug? Intentional change in behavior? Thanks, Adam
>

Intentional.

https://github.com/pgjdbc/pgjdbc/commit/9109451c65d43328b8e4344642331d7750d79cf6

​Not translating values embedded in string literals, dollar-quoted or
otherwise, seems like it is the correct way to operate - though finding an
authoritative source on the topic wasn't quick (so I gave up...).

David J.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-03-11 01:05 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10 23:10 JDBC escaped scalar functions fail when used in function definition Adam Rauch <adam@labkey.com>
2016-03-11 01:05 ` David G. Johnston <david.g.johnston@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox