Re: Any way to *not* use server-side prepared statements in Postgresql? - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: Any way to *not* use server-side prepared statements in Postgresql?
Date
Msg-id CA+0W9LN0RhFTQ1wz415zKAz4Uky35MgWU8xjohfNobfk_A4m2g@mail.gmail.com
Whole thread Raw
In response to Any way to *not* use server-side prepared statements in Postgresql?  (Yang Zhang <yanghatespam@gmail.com>)
Responses Re: Any way to *not* use server-side prepared statements in Postgresql?
List pgsql-jdbc
On 19 July 2011 14:07, Yang Zhang <yanghatespam@gmail.com> wrote:

> However, in Java, issuing:
>
>    conn.createStatement().executeQuery("select * from account where
> id = '00100000006ONCrAAO'");

You probably want to be using a PreparedStatement here anyway (it's
just good practice to let the driver worry about parameter value
escaping etc, especially given that the rules are a bit variable
depending on server version)

> results in:
>
>    2011-07-18 18:44:59 PDT LOG:  duration: 4.353 ms  parse <unnamed>:
> select * from account where id = '00100000006ONCrAAO'
>    2011-07-18 18:44:59 PDT LOG:  duration: 0.230 ms  bind <unnamed>:
> select * from account where id = '00100000006ONCrAAO'
>    2011-07-18 18:44:59 PDT LOG:  duration: 0.246 ms  execute
> <unnamed>: select * from account where id = '00100000006ONCrAAO'
>
> Some searching shows that the PG JDBC driver *always* uses prepared
> statements:
http://postgresql.1045698.n5.nabble.com/JDBC-prepared-statements-amp-server-side-prepared-statements-td1919506.html
>
> Is there any way to circumvent server prepared statements? If it makes
> a difference, I'm asking regarding PG 8.4 and 9.0. Thanks in advance.

You can use the v2 protocol (which inserts parameter values as text,
rather than sending them out of line), but you will lose various other
bits of driver functionality that depend on the v3 protocol.

Perhaps a better question is: Why do you want to avoid server prepared
statements?
If it is because you want more compact logging, perhaps there is
something that can be improved on the server side?

Oliver

pgsql-jdbc by date:

Previous
From: Yang Zhang
Date:
Subject: Re: Any way to *not* use server-side prepared statements in Postgresql?
Next
From: Maciek Sakrejda
Date:
Subject: Re: Any way to *not* use server-side prepared statements in Postgresql?