From: John R Pierce <pierce@hogranch.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Date: Wed, 26 Apr 2017 14:07:03 -0700
Message-ID: <eae3875c-9c21-faf7-9adb-6ab07465e553@hogranch.com> (raw)
In-Reply-To: <5f3b0581-8c2d-8323-73c7-e917da54c96c@hogranch.com>
References: <20170426182322.24371.95224@wrigleys.postgresql.org>
<CAKFQuwZ+PXKFrQ+LqOOorfva9nMesie0WQpe_hJTdkMn7vCZAw@mail.gmail.com>
<5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com>
<5f3b0581-8c2d-8323-73c7-e917da54c96c@hogranch.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 4/26/2017 1:53 PM, John R Pierce wrote:
> On 4/26/2017 1:30 PM, Pietro Pugni wrote:
>> Adding 10 years to 1912-02-29 returns 1922-02-29, as expected.
>> I would like to apply the *reverse* operation. To do so, I subtract
>> 10 years from 1922-02-29 but I obtain 1912-02-28, so *the math is
>> actually wrong*.
>
>
> assuming 1922 was a leap year, 1912 is NOT a leap year, so therefore
> there is no 1912-02-29, that is an invalid date.
>
ok, I got that backwards. 1912 is the leap year.
date arithmetic is not guaranteed to be associative or commutative due
to the irregular units involved.
pierce=# SELECT date '1912-02-29';
date
------------
1912-02-29
(1 row)
pierce=# SELECT date '1922-02-29';
ERROR: date/time field value out of range: "1922-02-29"
LINE 1: SELECT date '1922-02-29';
^
pierce=# SELECT date '1912-02-29' - interval '10 years';
?column?
---------------------
1902-02-28 00:00:00
(1 row)
pierce=# SELECT date '1912-02-29' + interval '10 years';
?column?
---------------------
1922-02-28 00:00:00
(1 row)
as an even more extreme case...
pierce=# SELECT date '2017-04-30' - interval '2 months';
?column?
---------------------
2017-02-28 00:00:00
(1 row)
--
john r pierce, recycling bits in santa cruz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: pierce@hogranch.com
Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
In-Reply-To: <eae3875c-9c21-faf7-9adb-6ab07465e553@hogranch.com>
References: <20170426182322.24371.95224@wrigleys.postgresql.org> <CAKFQuwZ+PXKFrQ+LqOOorfva9nMesie0WQpe_hJTdkMn7vCZAw@mail.gmail.com> <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com> <5f3b0581-8c2d-8323-73c7-e917da54c96c@hogranch.com> <eae3875c-9c21-faf7-9adb-6ab07465e553@hogranch.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox