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 1sezTP-00FPiL-Qb for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Aug 2024 16:06:43 +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 1sezTN-006Kzs-NK for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Aug 2024 16:06:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sezTN-006Kzi-De for pgsql-bugs@lists.postgresql.org; Fri, 16 Aug 2024 16:06:41 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sezTL-005B7E-7U for pgsql-bugs@lists.postgresql.org; Fri, 16 Aug 2024 16:06:40 +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 47GG6ZpQ761518; Fri, 16 Aug 2024 12:06:35 -0400 From: Tom Lane To: Bruce Momjian cc: jian he , 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: <222870.1708458150@sss.pgh.pa.us> <270582.1708462564@sss.pgh.pa.us> <166456.1715117228@sss.pgh.pa.us> <476283.1715177448@sss.pgh.pa.us> <1079670.1720458208@sss.pgh.pa.us> <755165.1723822675@sss.pgh.pa.us> Comments: In-reply-to Bruce Momjian message dated "Fri, 16 Aug 2024 11:52:38 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <761516.1723824395.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 16 Aug 2024 12:06:35 -0400 Message-ID: <761517.1723824395@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bruce Momjian writes: > On Fri, Aug 16, 2024 at 11:37:55AM -0400, Tom Lane wrote: >> But I'm starting to despair of reaching a solution that's actually >> self-consistent. Maybe we should leave the DTK_QUARTER behavior >> alone, and content ourselves with adding DTK_WEEK. > Well, I liked that -4 months actually was in -2 quarter. Yeah. On further reflection, I agree it's a bad idea for the DTK_QUARTER computation to depend on anything but the months field. So that lets out v3. However, what we have historically is regression=3D# select n, extract(quarter from interval '1 mon' * n) from g= enerate_series(-12,12) n; n | extract = -----+--------- -12 | 1 -11 | -2 -10 | -2 -9 | -2 -8 | -1 -7 | -1 -6 | -1 -5 | 0 -4 | 0 -3 | 0 -2 | 1 -1 | 1 0 | 1 1 | 1 2 | 1 3 | 2 4 | 2 5 | 2 6 | 3 7 | 3 8 | 3 9 | 4 10 | 4 11 | 4 12 | 1 (25 rows) which is fine on the positive side but it's hard to describe the results for negative months as anything but wacko. The v2 patch gives regression=3D# select n, extract(quarter from interval '1 mon' * n) from g= enerate_series(-12,12) n; n | extract = -----+--------- -12 | -1 -11 | -4 -10 | -4 -9 | -4 -8 | -3 -7 | -3 -6 | -3 -5 | -2 -4 | -2 -3 | -2 -2 | -1 -1 | -1 0 | 1 1 | 1 2 | 1 3 | 2 4 | 2 5 | 2 6 | 3 7 | 3 8 | 3 9 | 4 10 | 4 11 | 4 12 | 1 (25 rows) which is a whole lot saner. So let's run with v2. regards, tom lane