From: Tom Lane <tgl@sss.pgh.pa.us>
To: Pietro Pugni <pietro.pugni@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Date: Wed, 26 Apr 2017 17:25:18 -0400
Message-ID: <9066.1493241918@sss.pgh.pa.us> (raw)
In-Reply-To: <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com>
References: <20170426182322.24371.95224@wrigleys.postgresql.org>
<CAKFQuwZ+PXKFrQ+LqOOorfva9nMesie0WQpe_hJTdkMn7vCZAw@mail.gmail.com>
<5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Pietro Pugni <pietro.pugni@gmail.com> writes:
> Adding 10 years to 1912-02-29 returns 1922-02-29, as expected.
No, it doesn't, and it would be wrong to do so because there is no
such date; 1922 wasn't a leap year.
There are basically three things the addition operator could do here:
throw an error, return 1922-02-28, or return 1922-03-01. The first
choice seems rather unhelpful. The second choice is more in keeping
with what we do for some other similar cases, such as
regression=# select '2017-01-31'::date + '1 month'::interval;
?column?
---------------------
2017-02-28 00:00:00
(1 row)
regression=# select '2017-01-31'::date + '3 months'::interval;
?column?
---------------------
2017-04-30 00:00:00
(1 row)
Basically the thought is that the last day of the month is more likely
to be the answer the user wants for such cases than the first day of the
next month. If you want the less-fuzzy semantics of, say, "plus 30 days",
you can have that too but you need to say it that way.
The really short answer is that civil calendars were not invented by
mathematicians and expecting them to obey mathematical laws is doomed
to be an exercise in frustration.
> The bug basically consists of the vague meaning of “years” applied to
> leap years. It should be revised in order to be consistent and correct.
As remarked somewhere in our documentation, you'd need to take that up
with the Pope, not with us database hackers. We didn't invent the
calendar rules.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: tgl@sss.pgh.pa.us, pietro.pugni@gmail.com, david.g.johnston@gmail.com
Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
In-Reply-To: <9066.1493241918@sss.pgh.pa.us>
References: <20170426182322.24371.95224@wrigleys.postgresql.org> <CAKFQuwZ+PXKFrQ+LqOOorfva9nMesie0WQpe_hJTdkMn7vCZAw@mail.gmail.com> <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com> <9066.1493241918@sss.pgh.pa.us>
* 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