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

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Yang Zhang <yanghatespam(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Any way to *not* use server-side prepared statements in Postgresql?
Date: 2011-07-19 02:50:46
Message-ID: CA+0W9LN0RhFTQ1wz415zKAz4Uky35MgWU8xjohfNobfk_A4m2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 19 July 2011 14:07, Yang Zhang <yanghatespam(at)gmail(dot)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

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Yang Zhang 2011-07-19 03:03:30 Re: Any way to *not* use server-side prepared statements in Postgresql?
Previous Message Yang Zhang 2011-07-19 02:49:27 Re: Any way to *not* use server-side prepared statements in Postgresql?