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 1lR1sr-00031a-CC for pgsql-general@arkaria.postgresql.org; Tue, 30 Mar 2021 00:05:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lR1sq-00061Z-Ad for pgsql-general@arkaria.postgresql.org; Tue, 30 Mar 2021 00:05:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lR1sq-00061S-0l for pgsql-general@lists.postgresql.org; Tue, 30 Mar 2021 00:05:24 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lR1sn-0000ON-An for pgsql-general@lists.postgresql.org; Tue, 30 Mar 2021 00:05:23 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 87A8D5C0192; Mon, 29 Mar 2021 20:05:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 29 Mar 2021 20:05:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=f WVQDvoHEgQoUxMgSH7WJOOkKeHDGErDZWmHQ+Ho6Lg=; b=tE+l8wXnS6YwaFV2x HPQyc7gzvj6FIM5sBU5Kb6xrvPq8IkndkSBRos+yNw26ww3KHCy9n7Jz956n8ePT ghgi3PAHLdVAfrHqlKQWhvvqNAaWs5EOgvO8OhS3W9ydZh0dn2yugklct3OuZPVm UNyvlwN4NnvulNixJhvDEijMKSsXk/LURedKzz+4MBDI05+OxaQwcJP4IzCBHxOg Fu/Z6T6GLhA+03lVGGZLFW6ZXmkDe/j0ME+D/Eed8BR7sewOvAuQfBjI97V9eLkT xgSEYg0U4+UyDxrx0lHAYvC0pCpRFj/7WY3rrekbjnv8ZuS3e+L11+/uPYyEXDNq zt34Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=fWVQDvoHEgQoUxMgSH7WJOOkKeHDGErDZWmHQ+Ho6 Lg=; b=fLnaEPyPPKLhZcmvowTk0JVynmKatS9FdMqRm1KueqdaZOXH+gC/YB2h9 LR4Tcp57tLFLgGGg9j1bhy7UeO0tQrz9GcWQtm2rsn444cjGWKrey/H3A6rLW7uE E2pNzhB7CrjWIlDePhx7/E+ifcraz+STgyDv7xRW1gHMYlofbBiMTFrw4utjsLv5 r/eVLa+ocYE65MwtFc3ylS5jJ7IXgW1JS1VwFv33t3GYwXO2g/YDnFlbPWOXqMGW divnT35aaljhM1w5Nsli8KOuPKLnEUaqjVhuJm8jmZvlxkLp4CT1+kRGhv8wlF/5 IAvQ1TyHKbh3t2vTJfdYFh9sV6yBA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudehledgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeduudefjeetveffhefgudehtdfhvdetkeeiueehfeev veduteekleeuheegudehhfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cukfhppeeljedruddufedrvddujedrvdejnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomh X-ME-Proxy: Received: from [192.168.1.4] (97-113-217-27.tukw.qwest.net [97.113.217.27]) by mail.messagingengine.com (Postfix) with ESMTPA id 7FDA824005B; Mon, 29 Mar 2021 20:05:18 -0400 (EDT) Subject: Re: = t1 - t0 but t0 + i <> t1 when t1 and t2 timestamptz values and i is an interval value To: Bryn Llewellyn Cc: pgsql-general list References: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com> <1578541.1616765766@sss.pgh.pa.us> <5566CFAE-BC21-4B3B-BF3F-15D4ABDF1FA8@yugabyte.com> From: Adrian Klaver Message-ID: Date: Mon, 29 Mar 2021 17:05:17 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <5566CFAE-BC21-4B3B-BF3F-15D4ABDF1FA8@yugabyte.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/29/21 3:32 PM, Bryn Llewellyn wrote: >> On 27-Mar-2021, at 09:16, Adrian Klaver wrote: >> >> … > > Re Adrian’s quote of the doc thus: > >> Also, field values “to the right” of the least significant field allowed by the fields specification are silently discarded. > > Yes, I do take this point. But there’s some murkiness here. All of my tests confirm that, for example, the declaration “interval minute” to second” has the same effect as “interval day to second”. But you can’t even write “interval month to second” or “interval “year to second”. This suggests that there’s a hard boundary (using those words rather loosely) between “months” and > “days”. This is consistent with this statement from the SQL Standard (1992 edition): > > « There are two classes of intervals. One class, called year-month intervals, has an express or implied datetime precision that includes no fields other than YEAR and MONTH, though not both are required. The other class, called day-time intervals, has an express or implied interval precision that can include any fields other than YEAR or MONTH. » > > Oracle Database honors this by allowing only two spellings of interval declaration “year to month” and “day to second”. But the fact that PostgreSQL allows a bare “interval” declaration that allows values of all six fields (years, months, days, hours, minutes, and seconds) is at odds with this. (In fact, it allows no fewer than _fourteen_ distinct ways to declare an interval—but these condense into only seven semantically distinct declarations. https://www.postgresql.org/docs/12/datatype-datetime.html#DATATYPE-INTERVAL-INPUT "Also, a combination of years and months can be specified with a dash; for example '200-10' is read the same as '200 years 10 months'. (These shorter forms are in fact the only ones allowed by the SQL standard, and are used for output when IntervalStyle is set to sql_standard.)" My stock suggestion to anyway going over datatype-datetime.html and associated pages is to read them several times, take a break, then read them again several times. Then assume you still have not nailed down the if, and/or's, and buts and be prepared to go over them again. > > Red Adrian’s comment: > >> Looking for logic in dates/times/calendars is a recipe for a continuous pounding headache. Not the least because horological = cultural. > > I’m looking for a sufficient, and clear, way to describe the rules of what the PostgreSQL implementation actually does. And I want to believe that at least some logical thinking informed the design. I rehearsed my argument that a genuine, and useful, distinction can be made between the two terms of art in my reply to Francisco Olarte. I wrote: Again if you are looking for logic you are in the wrong place. If you really want to know what is going on then I suggest taking a look at the source, in particular: src/backend/utils/adt/datetime.c Bring aspirin and/or a stiff glass of something medicinal. > > « My claim is that there’s a genuine distinction to be drawn in the conceptual domain—and that this can be made independently of any particular computer system. I might say that “1 day” is simply the same thing as “24 hours”, in the same way that “1 foot” is the same as “12 inches”. But my discussion partner might argue with this saying that the length of one day is sometimes 23 hours and sometimes 25 hours due to the much-rehearsed arguments about DST. Here, I’d be thinking horologically and my discussion partner would be thinking culturally. Those two terms of art (or other equivalent ones) are useful to stop a fist fight breaking out by allowing each discussion partner to understand, and label, the other’s mental model—both of which have merit. > > Notice that the same argument could be had about the equivalence of “1 minute” and “60 seconds” in the light of the “leap second” phenomenon. It just happens that when we get to PostgreSQL, its Proleptic Gregorian Calendar implementation knows nothing of leap seconds. At least, this is how I interpret “because leap seconds are not handled” on the https://www.postgresql.org/docs/11/functions-datetime.html page. » > > Here’s an example where (as I believe) I can use these terms to advantage: > > When you subtract two timeztamptz values which are greater apart than 24 hours, the “days”, “hours”, “minutes”, and “seconds” fields of the resulting interval are populated using horological semantics. But when you add an interval value to a timeztamptz value, the value of the “days” field is added using cultural semantics but the value of the “hours” field is added using horological semantics. > > This is possibly what lies behind the design choice that the “days” and “hours” values are explicitly separately represented. > > > > -- Adrian Klaver adrian.klaver@aklaver.com