Re: now() and interval

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Travis Hoyt" <thoyt(at)npc(dot)net>
Cc: "Postgres" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: now() and interval
Date: 2002-04-03 16:03:54
Message-ID: 9555.1017849834@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Travis Hoyt" <thoyt(at)npc(dot)net> writes:
> Just curious, why does this date manipulation return the incorrect value
> based on the order of the operation?
> mydb=> select interval '1 month' + now();
> mydb=> select now() + interval '1 month';

Looking in pg_operator (or "\do +" in psql) shows that there is a
"timestamp plus interval" operator, but no "interval plus timestamp"
operator. So in the first case the system will pick one of the
available operators and then coerce your values to the appropriate
input datatypes. I'm too lazy to work out which pair of datatypes is
being selected, but a good bet is that the timestamp from now() is being
cut down to a date.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Ken Gerdes 2002-04-03 20:10:32 finding out about databases and tables
Previous Message Travis Hoyt 2002-04-03 15:06:00 now() and interval