Re: A date bug: number of day of October - Mailing list pgsql-bugs

From Peter Eisentraut
Subject Re: A date bug: number of day of October
Date
Msg-id Pine.LNX.4.21.0004141943520.401-100000@localhost.localdomain
Whole thread Raw
In response to A date bug: number of day of October  (Guillaume Perréal <perreal@lyon.cemagref.fr>)
Responses Re: A date bug: number of day of October
List pgsql-bugs
Guillaume Perréal writes:

> Try computing (replace XXXX with some differents years):
>     'XXXX-10-01'::datetime + '1 month'::interval
> Depending on the year, you can get 'XXXX-11-01' as expected or 'XXXX-10-31'
> which is bug.

In the CET zone (where you probably live) daylight savings time ends in
October, so it is true that

    1999-10-01 00:00:00 + (24h * 31 days) = 1999-10-31 23:00:00

Of course a month is not defined as "24h * 30/31 days" but instead as the
time between xxxx-yy-zz and xxxx-(yy+1)-zz, so the above could be condered
wrong. It is especially wrong that the same thing happens if you use DATE
instead of TIMESTAMP (or DATETIME, now deprecated).

You get the above behaviour between 1996 and 2037. Before 1996 you can
observe the same behaviour with September, because back then we switched
in September! The system is pretty smart. Of course after 2037 we're
doomed anyway.

The bottom line is that INTERVAL in its current implementation has
deficiencies and it's not SQL compliant either.


--
Peter Eisentraut                  Sernanders väg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden

pgsql-bugs by date:

Previous
From: Ronald Kuczek
Date:
Subject: Single backend crashes if postmaster running
Next
From: Ryan Kirkpatrick
Date:
Subject: Re: Minimal patches for PostgreSQL 7.0b3 on NetBSD/alpha 1.4.1....