Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 5C7549FA1DE for ; Wed, 6 Dec 2006 10:38:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 17432-10 for ; Wed, 6 Dec 2006 10:38:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id E3E779FA430 for ; Wed, 6 Dec 2006 10:38:17 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 06 Dec 2006 06:38:15 -0800 Subject: Re: Something wrong with binding timestamp values From: Mark Lewis To: Peter Eisentraut Cc: pgsql-jdbc@postgresql.org In-Reply-To: <200612061458.32156.peter_e@gmx.net> References: <200612061458.32156.peter_e@gmx.net> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Wed, 06 Dec 2006 06:38:15 -0800 Message-Id: <1165415895.9734.286.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27.rhel4.6) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/39 X-Sequence-Number: 16271 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"? >