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 1m8n0A-00032z-IT for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jul 2021 17:05:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m8n09-0005B3-IW for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jul 2021 17:05:49 +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 1m8n09-0005Av-B4 for pgsql-hackers@lists.postgresql.org; Wed, 28 Jul 2021 17:05:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m8n07-0008Nf-8b for pgsql-hackers@lists.postgresql.org; Wed, 28 Jul 2021 17:05:48 +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 16SH5iUv593115; Wed, 28 Jul 2021 13:05:45 -0400 From: Tom Lane To: Robert Haas cc: Bruce Momjian , Bryn Llewellyn , pgsql-hackers list Subject: Re: Have I found an interval arithmetic bug? In-reply-to: References: <20210402180549.GF9270@momjian.us> <20210402234943.GB29126@momjian.us> <95D98B9E-CD54-4FAC-9574-D950E9741CAC@yugabyte.com> <20210403010229.GE29126@momjian.us> <20210727193614.GE19774@momjian.us> <456756.1627416114@sss.pgh.pa.us> <588727.1627487554@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Wed, 28 Jul 2021 12:32:03 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <593113.1627491944.1@sss.pgh.pa.us> Date: Wed, 28 Jul 2021 13:05:44 -0400 Message-ID: <593114.1627491944@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Wed, Jul 28, 2021 at 11:52 AM Tom Lane wrote: >> You know, I was thinking exactly that thing earlier. Changing the >> on-disk representation is certainly a nonstarter, but the problem >> here stems from expecting interval_in to do something sane with inputs >> that do not correspond to any representable value. I do not think we >> have any other datatypes where we expect the input function to make >> choices like that. > A case that is perhaps more theoretically similar to the instance at > hand is rounding during the construction of floating point values. My > system thinks '1.00000000000000000000000001'::float = '1'::float, so > in that case, as in this one, we've decided that it's OK to build an > inexact representation of the input value. Fair point, but you decided when you chose to use float that you don't care about the differences between numbers that only differ at the seventeenth or so decimal place. (Maybe, if you don't understand what float is, you didn't make that choice intentionally ... but that's a documentation issue not a code shortcoming.) However, it's fairly hard to believe that somebody who writes '1.4 years'::interval doesn't care about the 0.4 year. The fact that we silently convert that to, effectively, 1.33333333... years seems like a bigger roundoff error than one would expect. > I am dubious that it's worth the pain of making the input function > reject cases involving fractional units. It's true that some people > here aren't happy with the current behavior, but they may no happier > if we reject those cases with an error, and other people may then be > unhappy too. Maybe. A possible compromise is to accept only exactly-representable fractions. Then, for instance, we'd take 1.5 years (resulting in 18 months) but not 1.4 years. Now, this might fall foul of your point about not wanting to mislead people into expecting the system to do things it can't; but I'd argue that the existing behavior misleads them much more. > I think your previous idea was the best one so far: fix > the input function so that 'X years Y months' and 'Y months X years' > always produce the same answer, and call it good. That would clearly be a bug fix. I'm just troubled that there are still behaviors that people will see as bugs. regards, tom lane