Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id CB5A59FB646 for ; Tue, 3 Apr 2007 06:34:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 26861-02 for ; Tue, 3 Apr 2007 06:34:00 -0300 (ADT) X-Greylist: delayed 00:05:25.492717 by SQLgrey-1.7.4 Received: from smtp1web.tin.it (smtp1web.tin.it [212.216.176.195]) by postgresql.org (Postfix) with ESMTP id 3B4909FB661 for ; Tue, 3 Apr 2007 06:34:00 -0300 (ADT) Received: from pswm1.cp.tin.it (192.168.70.12) by smtp1web.tin.it (7.2.072.1) id 46110B2100021E89 for pgsql-jdbc@postgresql.org; Tue, 3 Apr 2007 11:28:29 +0200 Message-ID: <111b6c6205e.ste.buffaishere@tin.it> Date: Tue, 3 Apr 2007 10:28:29 +0100 (GMT+01:00) From: "ste.buffaishere@tin.it" Reply-To: "ste.buffaishere@tin.it" To: pgsql-jdbc@postgresql.org Subject: Prepared statement parameter and timestamp Mime-Version: 1.0 Content-Type: text/plain;charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: 82.88.141.86 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.201 tagged_above=0 required=5 tests=BAYES_50=0.001, DNS_FROM_RFC_ABUSE=0.2 X-Spam-Level: X-Archive-Number: 200704/4 X-Sequence-Number: 16853 Why this code: PreparedStatement ps = conn.prepareStatement( "SELECT date_trunc('week', {ts ?})"); ps.setTimestamp(1, new java.sql. Timestamp( new java.util.Date().getTime())); ResultSet rs = ps. executeQuery(); while(rs.next()) { debug(rs.getString(1)); } fails miserably with org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1" at org.postgresql.core.v3. QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1531) at org.postgresql.core.v3.QueryExecutorImpl.processResults (QueryExecutorImpl.java:1313) at org.postgresql.core.v3. QueryExecutorImpl.execute(QueryExecutorImpl.java:188) at org. postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement. java:452) at org.postgresql.jdbc2.AbstractJdbc2Statement. executeWithFlags(AbstractJdbc2Statement.java:354) at org. postgresql.jdbc2.AbstractJdbc2Statement.executeQuery (AbstractJdbc2Statement.java:258)