Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d41pf-0007Yi-E3 for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Apr 2017 09:04:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d41pf-0001Td-0G for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Apr 2017 09:04:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d41ow-0007SB-Pw for pgsql-bugs@postgresql.org; Fri, 28 Apr 2017 09:04:10 +0000 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1d41ou-0007tF-40 for pgsql-bugs@postgresql.org; Fri, 28 Apr 2017 09:04:09 +0000 Received: by mail-wr0-x22c.google.com with SMTP id w50so30131051wrc.0 for ; Fri, 28 Apr 2017 02:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc:message-id:references :to; bh=mcmn7Drz/1/1cGlZhTuLZQqe9EJXctNRSZVk87EZfps=; b=OIMRu4NEypMKPVKNRe9FKn0v3wP8VmQWmyKzenFHMOhzwwRJwHAHIIr63vyxM+aq81 tF6zv/qXQmhvFyGv/1F4x6XTEGX6rbVTSw7MBzhvC8gSpANikRIu2dQ1r8ZB4hKu5FBy zaoGlmuULl3TeGMdomgAqX0xVlq0noGeC87tJzYHumqOLxOTrywoU7D/ULlI688ZdPWo YidsE/BOyQGpJbywwVjHFWK9LyyphYOWUQ+fR55GWRfyJMJLitw7SfdOZoE0K/nm4mCy IrrQMrtaS+9I3uzLBu/0AP8Ve1MANI5eY0qbV4g4E6yREbtBckgTR9Z8ZV7gK8aRP3j8 TFXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=mcmn7Drz/1/1cGlZhTuLZQqe9EJXctNRSZVk87EZfps=; b=m6vrY0ueoD6jnkczEcau1B2Xo2uqZyoXJlY3PmHSyFpOog2mHK7mhw3Ysz8vJd6N2s QlikGl1V6wAHq9Cr1cr/4EtGM1LyqKBGGqEQ+6KT9kq/Pz6d7a1JTFAHubQgstrhcw4C DneA7wGtmWuljqj8R8sl54yzeKVyk8gcmrh5oKVS28h5BixhTIqhttUa7YgpKY8f31oO iYoFSfnaVpZafmBsUNGzL/wA+LCtPM0ckbx/U5cohz0wImp605Cyj/qvb3y4IdmiPvp+ 2HXkvt1DPDWAENu6Qw21sXB28a5ceRktaKGGwqee/y4/5NX5bA/ik8gpsXUDu7atJWMb hjIg== X-Gm-Message-State: AN3rC/7RFrPfQEOawENsja3hnLF1TmBW40w7wLgIj4O+6oDbPZrbsUUE LRMWCSSQETSiYQ== X-Received: by 10.223.129.4 with SMTP id 4mr7580664wrm.62.1493370246292; Fri, 28 Apr 2017 02:04:06 -0700 (PDT) Received: from [192.168.2.5] (2-230-140-245.ip202.fastwebnet.it. [2.230.140.245]) by smtp.gmail.com with ESMTPSA id t85sm6808222wmt.23.2017.04.28.02.04.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Apr 2017 02:04:05 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_1700668F-591C-47B3-9BA7-D2452E8E607A" Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals. From: Pietro Pugni In-Reply-To: Date: Fri, 28 Apr 2017 11:04:01 +0200 Cc: Marko Tiikkaja , "David G. Johnston" , "pgsql-bugs@postgresql.org" , Tom Lane Message-Id: <07CA08CB-78FB-42F6-832F-F9F7B838C1A6@gmail.com> References: <20170426182322.24371.95224@wrigleys.postgresql.org> <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com> <6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com> To: Pantelis Theodosiou X-Mailer: Apple Mail (2.3124) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --Apple-Mail=_1700668F-591C-47B3-9BA7-D2452E8E607A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > Il giorno 27 apr 2017, alle ore 14:31, Pantelis Theodosiou = ha scritto: >=20 > You seem to think that expressions similar to these should yield the = same results: >=20 > dateD + intervalA + intervalB >=20 > (dateD + intervalA) + intervalB >=20 > dateD + (intervalA + intervalB) >=20 > 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. >=20 > 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=20 >=20 > SELECT=20 > '2017-03-31'::date + '1 month'::interval + '1 month'::interval, > '2017-03-31'::date + ('1 month'::interval + '1 month'::interval) ; >=20 > Not all months have the same number of days and there is not a way to = fix that. >=20 > 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?=20 >=20 > Regards,=20 > 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= --Apple-Mail=_1700668F-591C-47B3-9BA7-D2452E8E607A Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
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
= --Apple-Mail=_1700668F-591C-47B3-9BA7-D2452E8E607A--