pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
setObject type for Interval objects
2+ messages / 2 participants
[nested] [flat]

* setObject type for Interval objects
@ 2007-06-28 09:58 David Goodenough <david.goodenough@btconnect.com>
  2007-06-28 13:00 ` Re: setObject type for Interval objects Albe Laurenz <all@adv.magwien.gv.at>
  0 siblings, 1 reply; 2+ messages in thread

From: David Goodenough @ 2007-06-28 09:58 UTC (permalink / raw)
  To: pgsql-jdbc

I have an SQL SELECT which contains an expressions of the form:-

WHERE created < CURRENT_TIMESTAMP - ?

where created is a TIMESTAMP field.  As a parameter I want to pass 
an interval, so I used:-

PGInterval interval = new PGInterval( intervalPeriod);
stmt.setObject( 1, interval);

but Postgresql objects with:-

org.postgresql.util.PSQLException: Can't infer the SQL type to use for an 
instance of org.postgresql.util.PGInterval. Use setObject() with an explicit 
Types value to specify the type to use.

So I guess I need the three parameter setObject, but I do not know what
type to pass to the third parameter.  I have googled, but to no avail (I 
obviously asked the wrong question).

David



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

* Re: setObject type for Interval objects
  2007-06-28 09:58 setObject type for Interval objects David Goodenough <david.goodenough@btconnect.com>
@ 2007-06-28 13:00 ` Albe Laurenz <all@adv.magwien.gv.at>
  0 siblings, 0 replies; 2+ messages in thread

From: Albe Laurenz @ 2007-06-28 13:00 UTC (permalink / raw)
  To: David Goodenough *EXTERN* <david.goodenough@btconnect.com>; pgsql-jdbc

David Goodenough wrote:
> 
> I have an SQL SELECT which contains an expressions of the form:-
> 
> WHERE created < CURRENT_TIMESTAMP - ?
> 
> where created is a TIMESTAMP field.  As a parameter I want to pass
> an interval, so I used:-
> 
> PGInterval interval = new PGInterval( intervalPeriod);
> stmt.setObject( 1, interval);
> 
> but Postgresql objects with:-
> 
> org.postgresql.util.PSQLException: Can't infer the SQL type
> to use for an instance of org.postgresql.util.PGInterval.
> Use setObject() with an explicit Types value to specify
> the type to use.

Strange - here (postgresql-8.2-505.jdbc3.jar with JDK 1.5.0_12-b04)
the following code runs fine:

  Connection conn = DriverManager.getConnection();
  PreparedStatement stmt = conn.prepareStatement(
                                "SELECT current_timestamp - ?");
  stmt.setObject(1, new PGInterval("2 days"));
  ResultSet rs = stmt.executeQuery();

Yours,
Laurenz Albe



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


end of thread, other threads:[~2007-06-28 13:00 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-06-28 09:58 setObject type for Interval objects David Goodenough <david.goodenough@btconnect.com>
2007-06-28 13:00 ` Albe Laurenz <all@adv.magwien.gv.at>

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