From: Justin Pryzby <pryzby@telsasoft.com>
To: Bruce Momjian <bruce@momjian.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: Zhihong Yu <zyu@yugabyte.com>
Cc: Isaac Morland <isaac.morland@gmail.com>
Cc: John W Higgins <wishdev@gmail.com>
Cc: pgsql-hackers@postgresql.org, Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: Have I found an interval arithmetic bug?
Date: Mon, 5 Apr 2021 11:33:10 -0500
Message-ID: <20210405163310.GP6592@telsasoft.com> (raw)
In-Reply-To: <E34DA978-0C0E-4F43-97CD-278FA0C228E5@yugabyte.com> <20210403022126.GG29126@momjian.us>
On Fri, Apr 02, 2021 at 10:21:26PM -0400, Bruce Momjian wrote:
> I wish I could figure out how to improve it any futher. What is odd is
> that I have never seen this reported as a problem before. I plan to
> apply this early next week for PG 14.
On Fri, Apr 02, 2021 at 01:05:42PM -0700, Bryn Llewellyn wrote:
> bruce@momjian.us wrote:
> > Yes, looking at the code, it seems we only spill down to one unit, not more. I think we need to have a discussion if we want to change that.
If this is a bug, then there's no deadline - and if you're proposing a behavior
change, then I don't think it's a good time to begin the discussion.
> https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-INTERVAL-INPUT
> « …field values can have fractional parts; for example '1.5 week' or '01:02:03.45'. Such input is converted to the appropriate number of months, days, and seconds for storage. When this would result in a fractional number of months or days, the fraction is added to the lower-order fields using the conversion factors 1 month = 30 days and 1 day = 24 hours. For example, '1.5 month' becomes 1 month and 15 days. Only seconds will ever be shown as fractional on output. »
Your patch changes what seems to be the intended behavior, with the test case
added by:
|commit 57bfb27e60055c10e42b87e68a894720c2f78e70
|Author: Tom Lane <tgl@sss.pgh.pa.us>
|Date: Mon Sep 4 01:26:28 2006 +0000
|
| Fix interval input parser so that fractional weeks and months are
| cascaded first to days and only what is leftover into seconds. This
And documented by:
|commit dbf57d31f8d7bf5c058a9fab2a1ccb4a336864ce
|Author: Tom Lane <tgl@sss.pgh.pa.us>
|Date: Sun Nov 9 17:09:48 2008 +0000
|
| Add some documentation about handling of fractions in interval input.
| (It's always worked like this, but we never documented it before.)
If you were to change the behavior, I think you'd have to update the
documentation, too - but I think that's not a desirable change.
I *am* curious why the YEAR, DECADE, CENTURY, AND MILLENIUM cases only handle
fractional intervals down to the next smaller unit, and not down to
seconds/milliseconds. I wrote a patch to handle that by adding
AdjustFractMons(), if we agree that it's desirable to change.
--
Justin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: pryzby@telsasoft.com, bruce@momjian.us, bryn@yugabyte.com, zyu@yugabyte.com, isaac.morland@gmail.com, wishdev@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: Have I found an interval arithmetic bug?
In-Reply-To: <20210405163310.GP6592@telsasoft.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox