From: Mark Lewis <mark.lewis@mir3.com>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Something wrong with binding timestamp values
Date: Wed, 06 Dec 2006 06:38:15 -0800
Message-ID: <1165415895.9734.286.camel@archimedes> (raw)
In-Reply-To: <200612061458.32156.peter_e@gmx.net>
References: <200612061458.32156.peter_e@gmx.net>
It's to work around the fact that JDBC only knows about one Timestamp
type, while PG knows about more. It ends up being better in most cases
to send the type as unknown and let the server disambiguate to the
correct type than to guess about the type and maybe guess wrong.
This was a recent change, which is why it used to work for you but now
doesn't. It was known that cases like yours which call overloaded
functions may require an explicit cast, something like "SELECT
date_trunc('day', ?::timestamp)", but it was decided that it's better to
force a cast in some cases than to do things demonstrably wrong in other
cases (which the older driver versions were wont to do).
You can dig through the archives for more of the gory details.
-- Mark Lewis
On Wed, 2006-12-06 at 14:58 +0100, Peter Eisentraut wrote:
> This code
>
> PreparedStatement st = conn.prepareStatement("SELECT date_trunc('day', ?)");
> st.setString(1, "2006-12-17");
> ResultSet rs = st.executeQuery();
>
> fails, as might be expected, because date_trunc(unknown, varchar)
> doesn't exist.
>
> But this code:
>
> PreparedStatement st = conn.prepareStatement("SELECT date_trunc('day', ?)");
> st.setTimestamp(1, new Timestamp(222222222));
> ResultSet rs = st.executeQuery();
>
> fails with postgresql-8.1-408.jdbc3.jar with
>
> ERROR: function date_trunc("unknown", "unknown") is not unique
>
> It works correctly with postgresql-8.0-318.jdbc3.jar.
>
> What is wrong here? Why does a timestamp value end up being bound as
> "unknown"?
>
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: mark.lewis@mir3.com, peter_e@gmx.net
Subject: Re: Something wrong with binding timestamp values
In-Reply-To: <1165415895.9734.286.camel@archimedes>
References: <200612061458.32156.peter_e@gmx.net> <1165415895.9734.286.camel@archimedes>
* 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