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 1lQBcH-0003lz-Jf for pgsql-general@arkaria.postgresql.org; Sat, 27 Mar 2021 16:16:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lQBcE-0007Rd-AT for pgsql-general@arkaria.postgresql.org; Sat, 27 Mar 2021 16:16:46 +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 1lQBcC-0007OA-UY for pgsql-general@lists.postgresql.org; Sat, 27 Mar 2021 16:16:46 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lQBc4-0000H8-8Z for pgsql-general@lists.postgresql.org; Sat, 27 Mar 2021 16:16:44 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id B1D2B5C009B; Sat, 27 Mar 2021 12:16:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sat, 27 Mar 2021 12:16:32 -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=p mMSpwH3sSEpakeZJkFaBEFfVllOnIX8EUxeOsfR7Kc=; b=eSbo6PbiUH5ZWXKLU CCspzV6CbqtFaQyfoET3OT4bidoHhwiX2e7g+SW6StLxYV7BaYPb7uJs39Ke5q96 u8l8BszPttagnDI+OOzrNXx6rdL4P5CmUJhShirKSlaMR9kzc305XDadNu4hcFDb mxu7fm75jeJWrC37XzbAUoLikK3mSX52uf1Sc9FypQ7eENC2E+47oHyaBqLJv5cL rNgF6m1jTrRYOwdnUyzfHRHSnntnLNUDbmTOwIqiE4pd3OfNDA6vBkqwYIhfQ7oo AY8CYKfMuGN6FZouzWlzIJ+y9wN0Z6oWRV8ECYC4R1VZwj38jQITh1v/aje0/vw1 FLVGw== 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=pmMSpwH3sSEpakeZJkFaBEFfVllOnIX8EUxeOsfR7 Kc=; b=u1HLChnEp8y3RwL3NbARUQthYuc8XDQmabIkZ4hUbaGA5XItmGQKFEoj7 ijEXyTLdv0aFCeAaHbMzxyEgMrkG5s3LTJT2JUsA0AolB3xehUsUcn6mr8B4I7Tb MN3j1UhwvB+XdtxTHmaaXypIzGM2NdTy+h/LX+e9d4Cci2yrgkg8ED9D/BB2LFEi N+UhuJ5o5qxR3wEUKBlQTlG7s4ZppcxVUYrEbdv7hiUqCPD12NxYU4jnX7FjDXyD 5gJbu7kbtDiqPM5f9eHi9ZJLByPnhP1O6nQrloKMY+dZyYt4WIG8nYYi6yj71Y7y vTsDV78A9AN6ncrYNV7VJYJIW5GBw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudehgedgkeeiucetufdoteggodetrfdotf 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 7105C1080057; Sat, 27 Mar 2021 12:16:31 -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 , Tom Lane PostgreSQL , folarte@peoplecall.com Cc: pgsql-general list References: <402F8EFB-3FE9-421A-B3BA-F736AB8E3ABB@yugabyte.com> <1578541.1616765766@sss.pgh.pa.us> From: Adrian Klaver Message-ID: Date: Sat, 27 Mar 2021 09:16:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: 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/26/21 2:16 PM, Bryn Llewellyn wrote: > /Tom Lane wrote:/ > > Finally, I discovered that this is OK: > > *create table t(i interval);* > > But I can’t find a definition of the semantics of a bare interval. > However, I did find a column headed “Mixed Interval”  at > https://www.postgresql.org/docs/11/datatype-datetime.html#INTERVAL-STYLE-OUTPUT-TABLE > . > But the example values in the column are consistent with this: > > *select ((interval '2 years, 3 months, 4 days, 5 hours, 6 minutes 7.8 > seconds')::interval)::text as i;* > > This is the result: > > *2 years 3 mons 4 days 05:06:07.8* > > If you repeat the “select” using the typecast “*::interval month*” then > the other components are silently thrown away. But if you repeat it > using the typecast “*::interval second*” then all components are > preserved just as with bare “*interval*”. This muddies my idea that > there were three distinct interval flavors: horological, cultural, and > hybrid. Is the behavior that I’ve just shown intended? https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT "Also, field values “to the right” of the least significant field allowed by the fields specification are silently discarded. For example, writing INTERVAL '1 day 2:03:04' HOUR TO MINUTE results in dropping the seconds field, but not the day field." So you get: test(5432)=> select '2 years 3 mons 4 days 05:06:07.8'::interval month; interval ---------------- 2 years 3 mons (1 row) Equivalent to: test(5432)=> select '2 years 3 mons 4 days 05:06:07.8'::interval YEAR TO MONTH; interval ---------------- 2 years 3 mons test(5432)=> select '2 years 3 mons 4 days 05:06:07.8'::interval second; interval ---------------------------------- 2 years 3 mons 4 days 05:06:07.8 (1 row) Equivalent to: select '2 years 3 mons 4 days 05:06:07.8'::interval HOUR TO SECOND; interval ---------------------------------- 2 years 3 mons 4 days 05:06:07.8 (1 row) > > I can guess the rules for the outcome when such a hybrid is added to a > timestamptz value. It’s possible to design edge case tests where you’d > get different outcomes if: (a) the cultural component is added first and > only then the horological component is added; or (b) the components are > added in the other order. It seems to me that the outcome is governed by > rule (a). Am I right? > > B.t.w., I think that the specific complexities of the proleptic > Gregorian calendar are cleanly separable from the basic idea that > (considering only the requirements statement space) there is a real > distinction to be drawn between “horological” and “cultural”—no matter > what calendar rules might be used. Looking for logic in dates/times/calendars is a recipe for a continuous pounding headache. Not the least because horological = cultural. -- Adrian Klaver adrian.klaver@aklaver.com