From: Oliver Jowett <oliver@opencloud.com>
To: Eliézer Madeira de Campos <eliezer@diuno.com.br>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: 7.3 -> 8.0.4 migration timestamp problem
Date: Sat, 05 Nov 2005 14:33:26 +1300
Message-ID: <436C0BE6.3000403@opencloud.com> (raw)
In-Reply-To: <54CC7CADE26E884EB2BCEC863F5C1F70F9D27F@moscou.diuno.net>
References: <54CC7CADE26E884EB2BCEC863F5C1F70F9D27F@moscou.diuno.net>
Eliézer Madeira de Campos wrote:
>>> Timestamp ts = new Timestamp(c.getTimeInMillis());
>>> pst = con.prepareStatement("select date_trunc('day', TIMESTAMP ?)");
>>> pst.setObject(1, ts);
>
>
>>Use "CAST (? AS TIMESTAMP)" instead of "TIMESTAMP ?".
>
> Why should I, if "TIMESTAMP ?" works when I run the insert in psql (or via unprepared statement)?
There are lots of other places where you can't blindly use '?'
placeholders -- for example, you can't use them where a column or table
name is expected. Prepared statements aren't just textual substitution.
The 8.0 driver's implementation uses protocol-level parameter binding
that is roughly equivalent to PREPARE/EXECUTE at the SQL level. Try that
same query via PREPARE in psql and you will see that it fails in the
same way.
> That might be valid as a workaround, but it would cost me thousands changes in the application, so it's not really a solution to the problem.
You need to talk to the backend developers then -- it's a limitation of
the SQL grammar used by the backend.
As a workaround, set protocolVersion=2 as a URL parameter, but you will
lose other driver functionality if you do that (e.g. parameter
metadata), and the v2 protocol path will not stay around forever.
-O
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: oliver@opencloud.com, eliezer@diuno.com.br
Subject: Re: 7.3 -> 8.0.4 migration timestamp problem
In-Reply-To: <436C0BE6.3000403@opencloud.com>
References: <54CC7CADE26E884EB2BCEC863F5C1F70F9D27F@moscou.diuno.net> <436C0BE6.3000403@opencloud.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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