Skip site navigation (1) Skip section navigation (2)

Re: Something wrong with binding timestamp values

From: Mark Lewis <mark(dot)lewis(at)mir3(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Something wrong with binding timestamp values
Date: 2006-12-06 14:38:15
Message-ID: 1165415895.9734.286.camel@archimedes (view raw or flat)
Thread:
Lists: pgsql-jdbc
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"?
> 

In response to

Responses

pgsql-jdbc by date

Next:From: Vit TimchishinDate: 2006-12-06 14:46:28
Subject: Re: Something wrong with binding timestamp values
Previous:From: Peter EisentrautDate: 2006-12-06 13:58:31
Subject: Something wrong with binding timestamp values

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group