Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 8B1D69FB846 for ; Wed, 11 Apr 2007 10:21:40 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 26244-03 for ; Wed, 11 Apr 2007 10:21:28 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.175]) by postgresql.org (Postfix) with ESMTP id 991DF9FB859 for ; Wed, 11 Apr 2007 10:21:33 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id k3so95846ugf for ; Wed, 11 Apr 2007 06:21:31 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding:sender; b=tEVo4DC7E/HkcdSGjqd91K0TNT2jRIzvl1Kmv8ZQAWDrPegYwslkVY3RFSyiYnCdJOEYfNiUwRUIGuxKULYh24yi687gQFDELMIX3nu52POtc4c2uiVGwOw6TPoI/0R5BXCBCkG+igbUpTEussWkiG9XE586kjgEXMcFhpK8/go= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding:sender; b=kduiNt9zbPm4Qg4s9QDLWVD8hws//L2c+xwScuAfRgv1KpOt2YwLAtVXbWCmptxWTsFvF2rY6fSXNYjbgBxlox4RQ0mTnCTVCut0RIUYO16kEIhdPWMyBSSehDvDQsZJx1Iql+Fn034zRQoiosINexVHSmiMkjkBmsQqvXzh1S0= Received: by 10.66.252.18 with SMTP id z18mr443529ugh.1176297691851; Wed, 11 Apr 2007 06:21:31 -0700 (PDT) Received: from ?192.168.1.32? ( [82.247.148.168]) by mx.google.com with ESMTP id j1sm2112849ugf.2007.04.11.06.21.30; Wed, 11 Apr 2007 06:21:31 -0700 (PDT) Message-ID: <461CE0D9.1090609@free.fr> Date: Wed, 11 Apr 2007 15:21:29 +0200 From: "Xavier Poinsard" User-Agent: Thunderbird 1.5.0.10 (X11/20070306) MIME-Version: 1.0 To: "ste.buffaishere@tin.it" CC: pgsql-jdbc@postgresql.org Subject: Re: Prepared statement parameter and timestamp References: <111b6c6205e.ste.buffaishere@tin.it> In-Reply-To: X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/20 X-Sequence-Number: 16869 Kris Jurka a écrit : > On Tue, 3 Apr 2007, ste.buffaishere@tin.it wrote: > >> PreparedStatement ps = conn.prepareStatement( >> "SELECT date_trunc('week', {ts ?})"); >> ps.setTimestamp(1, new java.sql. >> Timestamp( >> new java.util.Date().getTime())); >> >> fails miserably with >> org.postgresql.util.PSQLException: ERROR: syntax >> error at or near "$1" The purpose of the {ts 'XXX'} JDBC escape syntax is to have a standard syntax to write timestamp literal values. But if you are using a PreparedStatement you should directly write : SELECT date_trunc('week',?). > > > The JDBC driver translates the escape sequence to: > > SELECT date_trunc('week', timestamp ?) > > but the server can't handle the prefix timestamp cast for anything other > than plain literals, so it doesn't work for the parameter. > > I suppose the driver should instead try to rewrite this as: > > SELECT date_trunc('week', ?::timestamp) > > I'm not sure how much work that would be to do. This is a one line change. > > Kris Jurka > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster >