Re: Time stamp issue - Mailing list pgsql-general

From Scott Marlowe
Subject Re: Time stamp issue
Date
Msg-id dcc563d10801100749m427fca94qa626da94216607d1@mail.gmail.com
Whole thread Raw
In response to Time stamp issue  (<kapil.munish@wipro.com>)
List pgsql-general
On Jan 8, 2008 8:51 AM,  <kapil.munish@wipro.com> wrote:
> DELETE from CONCURRENT_USER WHERE (now() - CONCURRENT_USER.TIME_STAMP) > ?
>
>
>
> Here the calculated value in '?' is not supported by the postgres as it was
> set as a double.
>
> I tried to cast it to a timestamp by using Timestamp timestamp = new
> Timestamp((java.sql.Date(rs.getTimestamp(time_stamp)).getTime());

When you subtract one timestamp from another, you get an interval, not
a timestamp.  I.e. now() - (now() - 5 minutes) gives a result of 5
minutes.

So, you need to replace the ? with 5 minutes, so your query looks
something like this:

DELETE from CONCURRENT_USER WHERE (now() - CONCURRENT_USER.TIME_STAMP)
> interval '5 minutes'
or this:
DELETE from CONCURRENT_USER WHERE (now() - CONCURRENT_USER.TIME_STAMP)
> '5 minutes'::interval
or this:
DELETE from CONCURRENT_USER WHERE (now() - CONCURRENT_USER.TIME_STAMP)
> cast('5 minutes' as interval)

pgsql-general by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: postgres 8.3 release date and 2008-01-07 Cumulative Security Update Release
Next
From: Clodoaldo
Date:
Subject: Re: 8.2.4 serious slowdown