Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1DA6F9FB485 for ; Mon, 9 Apr 2007 13:14:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 81678-02 for ; Mon, 9 Apr 2007 13:14:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id 779549FB499 for ; Mon, 9 Apr 2007 13:14:12 -0300 (ADT) Received: (qmail 8116 invoked by uid 1112); 9 Apr 2007 16:14:11 -0000 Date: Mon, 9 Apr 2007 12:14:11 -0400 (EDT) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: "ste.buffaishere@tin.it" cc: pgsql-jdbc@postgresql.org Subject: Re: Prepared statement parameter and timestamp In-Reply-To: <111b6c6205e.ste.buffaishere@tin.it> Message-ID: References: <111b6c6205e.ste.buffaishere@tin.it> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/11 X-Sequence-Number: 16860 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 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. Kris Jurka