pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
setting PreparedStatement parameter using "at time zone interval ?"
3+ messages / 2 participants
[nested] [flat]

* setting PreparedStatement parameter using "at time zone interval ?"
@ 2007-12-19 09:18 Matt Magoffin <postgresql.org@msqr.us>
  2007-12-19 15:48 ` Re: setting PreparedStatement parameter using "at time zone interval ?" Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Matt Magoffin @ 2007-12-19 09:18 UTC (permalink / raw)
  To: pgsql-jdbc

I'm using the latest 8.3 development driver against an 8.3 database. I
thought back in 8.1 I used to be able to use a PreparedStatement that
included something like

... date(l.created AT TIME ZONE INTERVAL ?)

but now I am always getting an exception like

org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"

I found if I changed the query to use this syntax:

... date(timezone(?::interval, l.created))

it worked fine. Should the former syntax be supported by the JDBC driver?

-- m@



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: setting PreparedStatement parameter using "at time zone interval ?"
  2007-12-19 09:18 setting PreparedStatement parameter using "at time zone interval ?" Matt Magoffin <postgresql.org@msqr.us>
@ 2007-12-19 15:48 ` Tom Lane <tgl@sss.pgh.pa.us>
  2007-12-19 19:06   ` Re: setting PreparedStatement parameter using "at time zone interval ?" Matt Magoffin <postgresql.org@msqr.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2007-12-19 15:48 UTC (permalink / raw)
  To: Matt Magoffin <postgresql.org@msqr.us>; +Cc: pgsql-jdbc

"Matt Magoffin" <postgresql.org@msqr.us> writes:
> I'm using the latest 8.3 development driver against an 8.3 database. I
> thought back in 8.1 I used to be able to use a PreparedStatement that
> included something like
> ... date(l.created AT TIME ZONE INTERVAL ?)

That might've worked back before the driver did real prepared
statements.  It's invalid syntax though, because typename before the
constant works only for simple literal string constants.  You got away
with it when the driver interpolated parameter values into the query as
string literals, but you can't do it anymore.

?::interval (or the full-blown CAST syntax) is the right way.

See
http://developer.postgresql.org/pgdocs/postgres/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
particularly 4.1.2.5.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: setting PreparedStatement parameter using "at time zone interval ?"
  2007-12-19 09:18 setting PreparedStatement parameter using "at time zone interval ?" Matt Magoffin <postgresql.org@msqr.us>
  2007-12-19 15:48 ` Re: setting PreparedStatement parameter using "at time zone interval ?" Tom Lane <tgl@sss.pgh.pa.us>
@ 2007-12-19 19:06   ` Matt Magoffin <postgresql.org@msqr.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Matt Magoffin @ 2007-12-19 19:06 UTC (permalink / raw)
  To: pgsql-jdbc

> That might've worked back before the driver did real prepared
> statements.  It's invalid syntax though, because typename before the
> constant works only for simple literal string constants.  You got away
> with it when the driver interpolated parameter values into the query as
> string literals, but you can't do it anymore.
>
> ?::interval (or the full-blown CAST syntax) is the right way.
>
> See
> http://developer.postgresql.org/pgdocs/postgres/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
> particularly 4.1.2.5.

Thank you for the clarification.

-- m@




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2007-12-19 19:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-12-19 09:18 setting PreparedStatement parameter using "at time zone interval ?" Matt Magoffin <postgresql.org@msqr.us>
2007-12-19 15:48 ` Tom Lane <tgl@sss.pgh.pa.us>
2007-12-19 19:06   ` Matt Magoffin <postgresql.org@msqr.us>

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