Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcW0o-000WOO-6x for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Feb 2024 19:42:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rcW0m-001JRs-Eb for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Feb 2024 19:42:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcW0m-001JRj-6j for pgsql-bugs@lists.postgresql.org; Tue, 20 Feb 2024 19:42:40 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcW0f-0002Sp-1k for pgsql-bugs@lists.postgresql.org; Tue, 20 Feb 2024 19:42:39 +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 41KJgUBL222871; Tue, 20 Feb 2024 14:42:30 -0500 From: Tom Lane To: jian he cc: Francisco Olarte , Michael Bondarenko , pgsql-bugs@lists.postgresql.org, dgrowleyml@gmail.com, Peter Eisentraut Subject: Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL); In-reply-to: References: <18348-b097a3587dfde8a4@postgresql.org> <3709307.1708201825@sss.pgh.pa.us> <3749306.1708222748@sss.pgh.pa.us> Comments: In-reply-to jian he message dated "Tue, 20 Feb 2024 11:56:29 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <222869.1708458150.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 20 Feb 2024 14:42:30 -0500 Message-ID: <222870.1708458150@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk jian he writes: > On Sun, Feb 18, 2024 at 2:14 AM Tom Lane wrote: >> (Parenthetically, one case that perhaps is surprising is >> ERROR: unit "week" not supported for type interval >> Why not just return the day field divided by 7?) > seems pretty simple? Hm, maybe, but does this behave desirably for zero or negative days? > So in section 9.9.1. EXTRACT, date_part > we may need to document extract(quarter from interval) case. > intervals can be negative, which will make the issue more complicated. > except the "quarter" field , EXTRACT other fields from intervals, the > output seems sane. Yeah, I see what you mean: the output for negative month counts is very bizarre, whereas other fields seem to all produce the negative of what they'd produce for the absolute value of the interval. We could either try to fix that or decide that rejecting "quarter" for intervals is the saner answer. I went ahead and pushed the docs changes after adding more explicit descriptions of interval's behavior for the field types where it seemed important. If we make any changes to the behavior for week or quarter fields, ISTM that should be a HEAD-only change. regards, tom lane