pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
INTERVAL parameter in PreparedStatement worked in 7.4 but not in 8.0 driver
4+ messages / 2 participants
[nested] [flat]

* INTERVAL parameter in PreparedStatement worked in 7.4 but not in 8.0 driver
@ 2005-10-27 23:56  Matt Magoffin <postgresql.org@msqr.us>
  0 siblings, 2 replies; 4+ messages in thread

From: Matt Magoffin @ 2005-10-27 23:56 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

I used to use the following style statement with the 7.4 series JDBC driver:

select * from users users where users.createdDate < (CURRENT_DATE -
INTERVAL ?)

and would set the parameter to a string value of "14 DAYS"

but in the Postgres 8 driver, this query executes but does not seem to
ever return anything. Is there a better syntax I could use to make this
work?

The query does work in the 8 driver if the ? is explicitly part of the
query, i.e. not a positional parameter, like this:

select * from users users where users.createdDate < (CURRENT_DATE -
INTERVAL '14 DAYS')

Any help much appreciated,
m@



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

* Re: INTERVAL parameter in PreparedStatement worked in 7.4
@ 2005-10-28 00:02  Matt Magoffin <postgresql.org@msqr.us>
  parent: Matt Magoffin <postgresql.org@msqr.us>
  1 sibling, 0 replies; 4+ messages in thread

From: Matt Magoffin @ 2005-10-28 00:02 UTC (permalink / raw)
  To: pgsql-jdbc

I forgot to add that the 8 driver throws an exception when trying to parse
the statement with the positional parameter:

java.sql.SQLException: ERROR: syntax error at or near "$1"

-- m@

> Hello,
>
> I used to use the following style statement with the 7.4 series JDBC
> driver:
>
> select * from users users where users.createdDate < (CURRENT_DATE -
> INTERVAL ?)
>
> and would set the parameter to a string value of "14 DAYS"
>
> but in the Postgres 8 driver, this query executes but does not seem to
> ever return anything. Is there a better syntax I could use to make this
> work?
>
> The query does work in the 8 driver if the ? is explicitly part of the
> query, i.e. not a positional parameter, like this:
>
> select * from users users where users.createdDate < (CURRENT_DATE -
> INTERVAL '14 DAYS')
>
> Any help much appreciated,
> m@




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

* Re: INTERVAL parameter in PreparedStatement worked in 7.4
@ 2005-10-28 00:29  Oliver Jowett <oliver@opencloud.com>
  parent: Matt Magoffin <postgresql.org@msqr.us>
  1 sibling, 1 reply; 4+ messages in thread

From: Oliver Jowett @ 2005-10-28 00:29 UTC (permalink / raw)
  To: Matt Magoffin <postgresql.org@msqr.us>; +Cc: pgsql-jdbc

Matt Magoffin wrote:

> I used to use the following style statement with the 7.4 series JDBC driver:
> 
> select * from users users where users.createdDate < (CURRENT_DATE -
> INTERVAL ?)
> 
> and would set the parameter to a string value of "14 DAYS"
> 
> but in the Postgres 8 driver, this query executes but does not seem to
> ever return anything. Is there a better syntax I could use to make this
> work?

"CAST (? AS INTERVAL)" should work.

Or use org.postgresql.util.PGInterval:

   stmt.setObject(1, new PGInterval("14 days"));

-O



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

* Re: INTERVAL parameter in PreparedStatement worked in
@ 2005-10-28 00:36  Matt Magoffin <postgresql.org@msqr.us>
  parent: Oliver Jowett <oliver@opencloud.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Matt Magoffin @ 2005-10-28 00:36 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc

Thank you, the CAST worked perfectly.

-- m@

> "CAST (? AS INTERVAL)" should work.
>
> Or use org.postgresql.util.PGInterval:
>
>    stmt.setObject(1, new PGInterval("14 days"));
>
> -O




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


end of thread, other threads:[~2005-10-28 00:36 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-27 23:56 INTERVAL parameter in PreparedStatement worked in 7.4 but not in 8.0 driver Matt Magoffin <postgresql.org@msqr.us>
2005-10-28 00:02 ` Re: INTERVAL parameter in PreparedStatement worked in 7.4 Matt Magoffin <postgresql.org@msqr.us>
2005-10-28 00:29 ` Re: INTERVAL parameter in PreparedStatement worked in 7.4 Oliver Jowett <oliver@opencloud.com>
2005-10-28 00:36   ` Re: INTERVAL parameter in PreparedStatement worked in 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