From: Kris Jurka <books@ejurka.com>
To: ste.buffaishere@tin.it <ste.buffaishere@tin.it>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Prepared statement parameter and timestamp
Date: Mon, 9 Apr 2007 12:14:11 -0400 (EDT)
Message-ID: <Pine.BSO.4.64.0704091208320.13571@leary.csoft.net> (raw)
In-Reply-To: <111b6c6205e.ste.buffaishere@tin.it>
References: <111b6c6205e.ste.buffaishere@tin.it>
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
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: books@ejurka.com, ste.buffaishere@tin.it
Subject: Re: Prepared statement parameter and timestamp
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>
* 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