Re: now() and interval - Mailing list pgsql-novice

From Tom Lane
Subject Re: now() and interval
Date
Msg-id 9555.1017849834@sss.pgh.pa.us
Whole thread Raw
In response to now() and interval  ("Travis Hoyt" <thoyt@npc.net>)
List pgsql-novice
"Travis Hoyt" <thoyt@npc.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

pgsql-novice by date:

Previous
From: "Travis Hoyt"
Date:
Subject: now() and interval
Next
From: "Ken Gerdes"
Date:
Subject: finding out about databases and tables