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 1pGZ4m-0003nl-HF for pgsql-general@arkaria.postgresql.org; Sat, 14 Jan 2023 05:27:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pGZ4l-0002yn-Bu for pgsql-general@arkaria.postgresql.org; Sat, 14 Jan 2023 05:27:31 +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 1pGZ4j-0002yd-SY for pgsql-general@lists.postgresql.org; Sat, 14 Jan 2023 05:27:31 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pGZ4f-0001MC-18 for pgsql-general@lists.postgresql.org; Sat, 14 Jan 2023 05:27:29 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 35E103200564; Sat, 14 Jan 2023 00:27:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sat, 14 Jan 2023 00:27:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1673674036; x= 1673760436; bh=0UqovBYEL8ff98DqK8G6sCumqVlfHLV7v7YMc/KMtM4=; b=M fT4Z+Hyu3BOnuEC8QoXfHW6ZEum0yr1p/7bPO0gD/aCmlLf949MZN13J3Q7HgnNZ y9Ws0p5/m7Ing6nETIpS/EBJu7NQQEqm0I6UiYYB4oF/HE1KV+FKllUeylYmGipQ F6EpA3KNx5B2RqXfX28AdHKIXe4p580VZo9oTenyraeWmgH432t90s9ck9jeJwTU JTO1OZAATwtOmcl0IOTj0A6zB+LexHv52kffr+xW2R1cVMUuxgr9p9s2bUTcUfwL tjd2FzfMuIX+n+2eA21Tw5huu2CgKdMxPxLaHFd7bVYmJ5O382GVnHtw4pVoyDcu FgojntCcYF7WTgW+iuBSg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1673674036; x= 1673760436; bh=0UqovBYEL8ff98DqK8G6sCumqVlfHLV7v7YMc/KMtM4=; b=K Ew/qtodrxHujfr8/mXw1TY24pobPBgiTocgaXg6EaNu0sSsz8Rvm3JcKF/R/idqV 2o2ZY2ZCUHwSo5Kry6Rdu8VTZThbe4xi5+9eZaOv/N0EwxX825FAbwFhBqYiYwf3 4qu7xuegiN7xGeGQnZKieEzsnUnPIK9ZZfVRblC10ZCoqGZcAgp+kUZcSWjkHoEz Bv0N91/iecINIh5tz/HyBZTua1oJHQ5a6+KiGHiH6ehED8G9lSXHnoLylYHW1V9/ EF9W+7pV0NhOWZOPJKNOA98OXx0pDCa7dqWkBGYsLIqPov+ppGxqyoMfXpUKdGTL cHhKRQ0bGxz8bWVS9jpBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrleelgdekiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfevfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeetleeggeegtdffledvvefgvddtfedugfevhfehgfei geekjeevgffgveefvdeiueenucffohhmrghinheprghgvghntgihqdhsohhfthifrghrvg drohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 14 Jan 2023 00:27:15 -0500 (EST) Message-ID: Date: Fri, 13 Jan 2023 21:27:15 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: Intervals and ISO 8601 duration Content-Language: en-US To: Ken Tanzer , Tom Lane Cc: Sebastien Flaesch , pgsql-general References: <953416.1673536094@sss.pgh.pa.us> <53c0b4d4-b80a-a35b-ce18-61058794c9bb@aklaver.com> <13f80fd5-6baf-e272-54c7-e72e32280643@aklaver.com> <892688.1673657835@sss.pgh.pa.us> From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/13/23 17:24, Ken Tanzer wrote: > On Fri, Jan 13, 2023 at 4:57 PM Tom Lane > wrote: > > > Given what extract() provides, > > stored months = years * 12 + months > > stored days = days > > stored usec = reconstruct from hours+minutes+seconds+microseconds > > Perhaps it wouldn't be a bad idea to provide a couple more extract() > keywords to make that easier. > > > Thanks Tom!  That helped me spell it out and understand it a little more > clearly.  Both to understand the non-identicalness, and to see the > specifics.  But yeah it would be nice if it was a little easier to > extract! :) > > WITH foo AS ( > WITH inters AS ( >      SELECT >          '1 day 2 hours'::interval AS i1, >          '26 hours'::interval AS i2 > ) > SELECT >      *, >     EXTRACT(YEARS FROM i1)*12 + EXTRACT(MONTHS FROM i1) AS i1_months, >     EXTRACT(DAYS FROM i1) AS i1_days, >     EXTRACT(HOURS FROM i1) * 60 * 60 * 1000 >         + EXTRACT(MINUTES FROM i1) * 60 * 1000 >         + EXTRACT(SECONDS FROM i1) * 1000 >         + EXTRACT(MICROSECONDS FROM i1) >     AS i1_msec, >     EXTRACT(YEARS FROM i2)*12 + EXTRACT(MONTHS FROM i2) AS i2_months, >     EXTRACT(DAYS FROM i2) AS i2_days, >     EXTRACT(HOURS FROM i2) * 60 * 60 * 1000 >         + EXTRACT(MINUTES FROM i2) * 60 * 1000 >         + EXTRACT(SECONDS FROM i2) * 1000 >         + EXTRACT(MICROSECONDS FROM i2) >     AS i2_msec, >     i1=i2 AS equals > FROM inters > ) > SELECT >     *, >     (i1_months=i2_months AND i1_days=i2_days AND i1_msec=i2_msec) AS > identical, >     i1_months * 30 * 24 * 60 * 60 * 1000 >         + i1_days * 24 * 60 * 60 * 1000 >         + i1_msec AS i1_msec_total, >     i2_months * 30 * 24 * 60 * 60 * 1000 >         + i2_days * 24 * 60 * 60 * 1000 >         + i2_msec AS i2_msec_total > > FROM foo; > > -[ RECORD 1 ]-+--------------- > i1            | 1 day 02:00:00 > i2            | 26:00:00 > i1_months     | 0 > i1_days       | 1 > i1_msec       | 7200000 > i2_months     | 0 > i2_days       | 0 > i2_msec       | 93600000 > equals        | t > identical     | f > i1_msec_total | 93600000 > i2_msec_total | 93600000 I don't see how the above answers, from your previous post, the below: 1) Is the internal representation in months, days and microseconds different for these two intervals? 2) (If no, what else is it that makes them non-identical?) 3) Is there a way to access the internal representation? What you have done is reformat the intervals and establish that the formatted values point back at equal and most probably identical values. > > Cheers, > Ken > -- > AGENCY Software > A Free Software data system > By and for non-profits > /http://agency-software.org/ / > /https://demo.agency-software.org/client > / > ken.tanzer@agency-software.org > (253) 245-3801 > > Subscribe to the mailing list >  to > learn more about AGENCY or > follow the discussion. -- Adrian Klaver adrian.klaver@aklaver.com