order of adding date & interval values?

From: Lev Lvovsky <lists1(at)sonous(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: order of adding date & interval values?
Date: 2002-05-03 00:26:12
Message-ID: Pine.BSF.4.21.0205021714390.87204-100000@renegade.pfksound.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hello,

using 7.2.1

is there any reason why the order of operations of the following query
would matter?

here's an example:

diw=# select interval '40 years' + date '2001-01-01' as test;
test
---------------------
2001-01-01 00:00:00
(1 row)

diw=# select date '2001-01-01' + interval '40 years' as test;
test
---------------------
2041-01-01 00:00:00
(1 row)

note how the first query doesn't return the proper response.

also, is there a difference between:
"interval('40 years') " and "interval '40 years' " ?

or

"date('2001-01-01')" and "date '2001-01-01' " ?

because only the query at the top of this message works, the following
doesn't:

diw=# select date('2001-01-01') + interval('40 years') as test;
ERROR: parser: parse error at or near "'"

I realize that answers my question, but why?

any help would be appreciated!!!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2002-05-03 00:29:21 Re: hexadecimal values
Previous Message Anna Dorofiyenko 2002-05-02 23:55:39 select from function