Re: interval and timestamp change? - Mailing list pgsql-sql

From Tom Lane
Subject Re: interval and timestamp change?
Date
Msg-id 25930.1012104455@sss.pgh.pa.us
Whole thread Raw
In response to Re: interval and timestamp change?  (Chris Ruprecht <chrup999@yahoo.com>)
List pgsql-sql
Chris Ruprecht <chrup999@yahoo.com> writes:
> Here is Tom's explanation from that time:
> TIME is a reserved word now, or at least more reserved than it used to
> be.  You'll need to write 'now'::time or CAST('now' AS time).  Sorry
> about that, but SQL92 requires it...

Actually there's nothing wrong with his 'now', though as Brent points
out CURRENT_TIMESTAMP would be more standards-compliant.  The real
problem is that INTERVAL is also a more-reserved word than it used to
be.  So instead of

SELECT interval(('1/30/02  12:30 pm'::timestamp) - 'now');
ERROR:  parser: parse error at or near "("

he needs

SELECT "interval"(('1/30/02  12:30 pm'::timestamp) - 'now');

or

SELECT (('1/30/02  12:30 pm'::timestamp) - 'now')::interval;

although since the difference of two timestamps is already an interval,
there's not really any need for the cast anyway.  So this is sufficient:

SELECT '1/30/02  12:30 pm'::timestamp - current_timestamp;
        regards, tom lane


pgsql-sql by date:

Previous
From: pgsql
Date:
Subject: options for no multiple rows?
Next
From: Bruce Momjian
Date:
Subject: Re: LIMIT Optimization