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

From: Pietro Pugni <pietro(dot)pugni(at)gmail(dot)com>
To: Pantelis Theodosiou <ypercube(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, "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>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Date: 2017-04-28 09:04:01
Message-ID: 07CA08CB-78FB-42F6-832F-F9F7B838C1A6@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> Il giorno 27 apr 2017, alle ore 14:31, Pantelis Theodosiou <ypercube(at)gmail(dot)com> ha scritto:
>
> You seem to think that expressions similar to these should yield the same results:
>
> dateD + intervalA + intervalB
>
> (dateD + intervalA) + intervalB
>
> dateD + (intervalA + intervalB)
>
> But they don't and they couldn't, as many others have mentioned already.
> Expressions 1 and 2 are equivalent but the 3rd is not.
>
> And we don't even need leap years to find such "wrong" results. We have leap seconds (which are rare) and leap months (which are pretty common although we don't call them leap months). Just try
>
> SELECT
> '2017-03-31'::date + '1 month'::interval + '1 month'::interval,
> '2017-03-31'::date + ('1 month'::interval + '1 month'::interval) ;
>
> Not all months have the same number of days and there is not a way to fix that.
>
> It's just not possible to squeeze 31 days in a 30-days month. What should '2017-03-31'::date + '1 month'::interval result and what should '2017-03-30'::date + '1 month'::interval result?
>
> Regards,
> Pantelis

Probably it should be worth it to implement a sort of age2(timestamp, timestamp) function that returns ages accounting for leap years, months, days and seconds, without changing the actual implementation of age(timestamp, timestamp).

Kind regards,
Pietro Pugni

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Pietro Pugni 2017-04-28 10:46:38 Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Previous Message henry_boehlert 2017-04-28 08:28:18 BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode