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 1seyr4-00FD27-Gm for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Aug 2024 15:27:06 +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 1seyr2-0061ZP-Hi for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Aug 2024 15:27:04 +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 1seyr2-0061ZG-2P for pgsql-bugs@lists.postgresql.org; Fri, 16 Aug 2024 15:27:04 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1seyqz-005Ah2-Iy for pgsql-bugs@lists.postgresql.org; Fri, 16 Aug 2024 15:27:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=jbLZyVTe7RePmyI8eiXkI0wsuMqiAg4ws10xLdFv+c8=; b=XxS8l It3LJWhhqoIbHYIWkCAkVera05KDMUXhNNVZH4YVZx9RjDevRN1QeKRiPD9W42wHjl8ngtvvNol5r M1W1rU+ckidEVi0c4rPIg7lix+8DGQrZu8mDVOkKOrfYaRwfcgiqypmbSlAUPbG/Te8x32DhpMe4n smqHdyxqRtREu4THFUs1L2irw8RI/yTTzF8JozsfOwAgGzXI6hoNwVBD+Z0yFnW4Q791MRmzBUF// Gn0yAeYQaJWKU6Xc5gl5yNwVj2DujMgVJ4NccCmQpeshTCvWSpCpf73AmXhJsZtIGglnN2fT8SOf7 7JA8WG6gb+zzNOokQxeDiDYE0CeQQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1seyqw-00319S-0L; Fri, 16 Aug 2024 11:26:58 -0400 Date: Fri, 16 Aug 2024 11:26:58 -0400 From: Bruce Momjian To: Tom Lane 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); Message-ID: References: <3749306.1708222748@sss.pgh.pa.us> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Aug 15, 2024 at 10:45:58PM -0400, Bruce Momjian wrote: > > We could fix that by examining the sign of the lower-order fields > > when month is zero, as in the v3 patch attached. However, I'm not > > at all sure this is really better than v2. Notably, it makes the > > documentation's statement that the result is "the month field > > divided by 3 plus 1" even more incomplete. I still don't really > > want to go into details about the behavior for negative intervals. > > OTOH if we did do that, I'd rather write a blanket statement > > about the result being the negative of the result for a positive > > interval. > > > > Thoughts? > > I tested master, patch version 2 and patch version 3 with some sample > extract() queires, attached. I like patch version 2. Patch version 3 > bothers me because "-600 days" is ignored if months is non-zero, and > used for its sign for zero month values, which seems odd to me; better > to ignore it. I think there are two more issues. In patch version 3, when months is zero and you check days, you should also check seconds if days is zero. I think the other issue is that zero months is a valid Q1 value, since months 0-2 are Q1; from master: SELECT extract(quarter FROM interval '0 months'); extract --------- 1 SELECT extract(quarter FROM interval '2 months'); extract --------- 1 SELECT extract(quarter FROM interval '3 months'); extract --------- 2 so the idea that we should adjust the sign for zero months quarter extract doesn't seem logical to me. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you.