Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pietro Pugni <pietro(dot)pugni(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Date: 2017-04-26 21:25:18
Message-ID: 9066.1493241918@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Pietro Pugni <pietro(dot)pugni(at)gmail(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2017-04-26 21:25:57 Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Previous Message David G. Johnston 2017-04-26 21:15:45 Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.