pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Xavier Poinsard <xpoinsard@free.fr>
To: ste.buffaishere@tin.it <ste.buffaishere@tin.it>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Prepared statement parameter and timestamp
Date: Wed, 11 Apr 2007 15:21:29 +0200
Message-ID: <461CE0D9.1090609@free.fr> (raw)
In-Reply-To: <Pine.BSO.4.64.0704091208320.13571@leary.csoft.net>
References: <111b6c6205e.ste.buffaishere@tin.it>
	<Pine.BSO.4.64.0704091208320.13571@leary.csoft.net>

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
> 






view thread (3+ messages)

Message-ID: <461CE0D9.1090609@free.fr>
Permalink:  ../461CE0D9.1090609@free.fr/
Also on:    postgresql.org/message-id/461CE0D9.1090609@free.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: xpoinsard@free.fr, ste.buffaishere@tin.it
  Subject: Re: Prepared statement parameter and timestamp
  In-Reply-To: <461CE0D9.1090609@free.fr>
  References: <111b6c6205e.ste.buffaishere@tin.it> <Pine.BSO.4.64.0704091208320.13571@leary.csoft.net> <461CE0D9.1090609@free.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox