| From: | Kris Jurka <books(at)ejurka(dot)com> |
|---|---|
| To: | "ste(dot)buffaishere(at)tin(dot)it" <ste(dot)buffaishere(at)tin(dot)it> |
| Cc: | pgsql-jdbc(at)postgresql(dot)org |
| Subject: | Re: Prepared statement parameter and timestamp |
| Date: | 2007-04-09 16:14:11 |
| Message-ID: | Pine.BSO.4.64.0704091208320.13571@leary.csoft.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
On Tue, 3 Apr 2007, ste(dot)buffaishere(at)tin(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bellur Ashwin | 2007-04-10 17:14:11 | Exception in running query |
| Previous Message | Kris Jurka | 2007-04-09 16:07:25 | Re: Problem with Running Query |