Re: 7.3 -> 8.0.4 migration timestamp problem

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Eliézer Madeira de Campos <eliezer(at)diuno(dot)com(dot)br>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: 7.3 -> 8.0.4 migration timestamp problem
Date: 2005-11-05 01:33:26
Message-ID: 436C0BE6.3000403@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

Browse pgsql-jdbc by date

  From Date Subject
Next Message pavi thra 2005-11-05 04:54:22 doubt
Previous Message Eliézer Madeira de Campos 2005-11-04 22:39:12 Re: 7.3 -> 8.0.4 migration timestamp problem