X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 19B1AD95D5 for ; Fri, 4 Nov 2005 21:33:32 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75084-05 for ; Sat, 5 Nov 2005 01:33:25 +0000 (GMT) X-Greylist: delayed 03:13:13.016219 by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by svr1.postgresql.org (Postfix) with ESMTP id CF7AFD9437 for ; Fri, 4 Nov 2005 21:33:26 -0400 (AST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1EYCvv-0005md-9K; Sat, 05 Nov 2005 14:33:27 +1300 Message-ID: <436C0BE6.3000403@opencloud.com> Date: Sat, 05 Nov 2005 14:33:26 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051009) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Eli=E9zer_Madeira_de_Campos?= Cc: "pgsql-jdbc@postgresql.org" Subject: Re: 7.3 -> 8.0.4 migration timestamp problem References: <54CC7CADE26E884EB2BCEC863F5C1F70F9D27F@moscou.diuno.net> In-Reply-To: <54CC7CADE26E884EB2BCEC863F5C1F70F9D27F@moscou.diuno.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.008] X-Spam-Score: 0.008 X-Spam-Level: X-Archive-Number: 200511/20 X-Sequence-Number: 14118 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