Skip site navigation (1) Skip section navigation (2)

Re: possibly a bug?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ewald Geschwinde <webmaster(at)geschwinde(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: possibly a bug?
Date: 2002-01-30 23:27:46
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Ewald Geschwinde <webmaster(at)geschwinde(dot)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;
(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);
 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

In response to

pgsql-novice by date

Next:From: Josh BerkusDate: 2002-01-30 23:29:47
Subject: Re: possibly a bug?
Previous:From: Ewald GeschwindeDate: 2002-01-30 23:05:31
Subject: possibly a bug?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group