Re: possibly a bug? - Mailing list pgsql-novice

From Tom Lane
Subject Re: possibly a bug?
Date
Msg-id 27628.1012433266@sss.pgh.pa.us
Whole thread Raw
In response to possibly a bug?  (Ewald Geschwinde <webmaster@geschwinde.net>)
List pgsql-novice
Ewald Geschwinde <webmaster@geschwinde.net> writes:
> beta=# SELECT ('2001-10-28'::date + '1 day'::interval)::date;
>   ?column?
> ------------
>  2001-10-28
> (1 row)

Try using date arithmetic, rather than timestamp arithmetic:

regression=# SELECT '2001-10-28'::date + 1;
  ?column?
------------
 2001-10-29
(1 row)

The problem with the other is that type interval considers '1 day'
to mean '24 hours', which is not what you want.  Since 10/28 is
a DST transition day (at least here in the USA), there's a difference.
What you're really getting is a timestamp addition:

regression=# SELECT ('2001-10-28'::date + '1 day'::interval);
        ?column?
------------------------
 2001-10-28 23:00:00-05
(1 row)

which doesn't produce the desired result when you coerce the timestamp
back to date.

However, adding a plain integer to a date will do what you want.

            regards, tom lane

pgsql-novice by date:

Previous
From: Ewald Geschwinde
Date:
Subject: possibly a bug?
Next
From: "Josh Berkus"
Date:
Subject: Re: possibly a bug?