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

Поиск
Список
Период
Сортировка
От Pietro Pugni
Тема Re: [BUGS] BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Дата
Msg-id 07CA08CB-78FB-42F6-832F-F9F7B838C1A6@gmail.com
обсуждение исходный текст
Ответ на Re: [BUGS] BUG #14632: Plus and minus operators inconsistency withleap years and year intervals.  (Pantelis Theodosiou <ypercube@gmail.com>)
Ответы Re: [BUGS] BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.  (Pietro Pugni <pietro.pugni@gmail.com>)
Список pgsql-bugs
Il giorno 27 apr 2017, alle ore 14:31, Pantelis Theodosiou <ypercube@gmail.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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: henry_boehlert@agilent.com
Дата:
Сообщение: [BUGS] BUG #14634: On Windows pg_basebackup should write tar to stdout inbinary mode
Следующее
От: Pietro Pugni
Дата:
Сообщение: Re: [BUGS] BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.