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 1m62Hr-0006br-27 for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jul 2021 02:48:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m62Hp-0006xH-PQ for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jul 2021 02:48:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m62Hp-0006x9-He for pgsql-hackers@lists.postgresql.org; Wed, 21 Jul 2021 02:48:41 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m62Hn-0002S7-7Q for pgsql-hackers@postgresql.org; Wed, 21 Jul 2021 02:48:40 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1m62Hi-0000X9-Kr; Tue, 20 Jul 2021 22:48:34 -0400 Date: Tue, 20 Jul 2021 22:48:34 -0400 From: Bruce Momjian To: Zhihong Yu Cc: Daniel Gustafsson , Bryn Llewellyn , Tom Lane PostgreSQL , Justin Pryzby , Isaac Morland , John W Higgins , PostgreSQL-development Subject: Re: Have I found an interval arithmetic bug? Message-ID: <20210721024834.GA8395@momjian.us> References: <20210508024204.GB27048@momjian.us> <076E1871-8446-405C-9561-29FA03F46A4A@yesql.se> <20210630163516.GA3304@momjian.us> <20210720041419.GA5882@momjian.us> <20210720225350.GB27025@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 20, 2021 at 05:13:37PM -0700, Zhihong Yu wrote: > On Tue, Jul 20, 2021 at 3:53 PM Bruce Momjian wrote: > With your patch, the following example (Coutesy Bryn) still shows fraction: > > # select (interval '1 month')*1.123; >        ?column? > ----------------------- >  1 mon 3 days 16:33:36 > (1 row)  > > Do you think the output can be improved (by getting rid of fraction) ? Well, I focused on how fractional units were processed inside of interval values. I never considered how multiplication should be handled. I have not really thought about how to handle that, but this example now gives me concern: SELECT INTERVAL '1.06 months 1 hour'; interval ----------------------- 1 mon 2 days 01:00:00 Notice that it rounds the '1.06 months' to '1 mon 2 days', rather than spilling to hours/minutes/seconds, even though hours is already specified. I don't see a better way to handle this than the current code already does, but it is something odd. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com If only the physical world exists, free will is an illusion.