Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lPmdH-00043T-7D for pgsql-general@arkaria.postgresql.org; Fri, 26 Mar 2021 13:36:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lPmdG-0001WV-5r for pgsql-general@arkaria.postgresql.org; Fri, 26 Mar 2021 13:36:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lPmdF-0001V9-UR for pgsql-general@lists.postgresql.org; Fri, 26 Mar 2021 13:36:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lPmdD-0001Dv-L9 for pgsql-general@lists.postgresql.org; Fri, 26 Mar 2021 13:36:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 12QDa6AE1578542; Fri, 26 Mar 2021 09:36:06 -0400 From: Tom Lane To: Bryn Llewellyn cc: pgsql-general list Subject: Re: i := t1 - t0 but t0 + i <> t1 when t1 and t2 timestamptz values and i is an interval value In-reply-to: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com> References: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com> Comments: In-reply-to Bryn Llewellyn message dated "Thu, 25 Mar 2021 20:28:03 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1578540.1616765766.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 26 Mar 2021 09:36:06 -0400 Message-ID: <1578541.1616765766@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bryn Llewellyn writes: > There's more. We see that while the two "interval second=E2=80=9D values= '1 day 01:00:00' and '25 hours' test as equal, the results of adding each= to the same timestamptz value are different. You're misunderstanding how it works. The whole point of these operations is that "+ '1 day'" should give the same civil time on the next day, even if a DST boundary intervened. Similarly, "+ '1 month'" tries to give the same day number in the next month, and "+ '1 year'" tries to give the same month/day in the next year, despite varying month and year lengths. (Obviously, there are edge cases where there is no such date, and you get some nearby date instead.) Smaller units are taken literally though, so you could add some large number of hours or seconds if you don't want these behaviors. > PLEASE STATE THE RULES THAT ALLOW THE BEHAVIOR OF THE BLOCK TO BE PREDIC= TED. If you are looking for simple predictable rules, I am afraid there is absolutely nothing about either the Gregorian calendar or daylight-savings time that you will like. > (I searched the doc but found nothing.) There's a specific discussion of the DST-boundary issue on this page: https://www.postgresql.org/docs/current/functions-datetime.html (search for the first mention of America/Denver). Not sure about how well the months and years cases are documented. regards, tom lane