Re: order of adding date & interval values?

From: Darren Ferguson <darren(at)crystalballinc(dot)com>
To: Lev Lvovsky <lists1(at)sonous(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: order of adding date & interval values?
Date: 2002-05-03 01:19:10
Message-ID: Pine.LNX.4.10.10205022114520.13370-100000@thread.crystalballinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Postgresql expects a date first from what i am seeing. You can't just have
40 years then add a date because what is the 40 years.

You are adding a specific date to 40 years which the parser says is not
correct and logically this is true.

You should always have the date first before you add any interval of time
to it.

The difference between date('2001-01-01') and date '2001-01-01' is this

date('2001-01-01') Postgres is thinking this is a function defined in the
database. So you will get the error message.

This is my 2 cents

HTH

Darren Ferguson

On Thu, 2 May 2002, Lev Lvovsky wrote:

> 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!!!
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-05-03 02:09:37 Re: select from function
Previous Message Darren Ferguson 2002-05-03 01:11:30 Re: select from function