pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bruce Momjian <bruce@momjian.us>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: John W Higgins <wishdev@gmail.com>
Cc: pgsql-hackers list <pgsql-hackers@lists.postgresql.org>
Subject: Re: Have I found an interval arithmetic bug?
Date: Fri, 30 Jul 2021 12:49:34 -0400
Message-ID: <1008623.1627663774@sss.pgh.pa.us> (raw)
In-Reply-To: <20210730160854.GA9600@momjian.us>
References: <95D98B9E-CD54-4FAC-9574-D950E9741CAC@yugabyte.com>
	<20210403010229.GE29126@momjian.us>
	<20210727193614.GE19774@momjian.us>
	<456756.1627416114@sss.pgh.pa.us>
	<20210727211314.GA23040@momjian.us>
	<901454CE-2C0D-4C49-ADAB-A094C03B7CB1@yugabyte.com>
	<CAPhAwGyccJZT-mXzHU1216Q-Z_xY3q+4TixzZ2sZf3hiPFe5tg@mail.gmail.com>
	<CAEZATCWaK0qdTiqxS=fM03VaKcfbYmSOV_JzqYDrVn2nSaMnFQ@mail.gmail.com>
	<20210728151916.GA15440@momjian.us>
	<20210730160439.GZ9600@momjian.us>
	<20210730160854.GA9600@momjian.us>

Bruce Momjian <bruce@momjian.us> writes:
> On Fri, Jul 30, 2021 at 12:04:39PM -0400, Bruce Momjian wrote:
>> Unless I hear more feedback, I plan to apply this doc patch to all
>> branches with the word "rounded" changed to "truncated" in the back
>> branches, and apply the rounded code changes to master.

> Now that I think of it, I will just remove the word "rounded" from the
> back branch docs so we are technically breaking the documented API less
> in PG 15.

I think your first idea was better.  Not documenting the behavior
doesn't make this not an API change; it just makes it harder for
people to understand what changed.

The doc patch itself is not exactly fine:

+     Field values can have fractional parts;  for example, <literal>'1.5
+     weeks'</literal> or <literal>'01:02:03.45'</literal>.  However,

I think "some field values", as it was worded previously, was better.
If you try to write 01.5:02:03, that is not going to be interpreted
as 1.5 hours.  (Hmm, I get something that seems quite insane:

regression=# select '01.5:02:03'::interval;
    interval    
----------------
 1 day 14:03:00
(1 row)

I wonder what it thinks it's doing there.)

This is wrong:

+     because interval internally stores only three integer units (months,
+     days, seconds), fractional units must be spilled to smaller units.

s/seconds/microseconds/ is probably enough to fix that.

+     For example, because months are approximated to equal 30 days,
+     fractional values of units greater than months is rounded to be the
+     nearest integer number of months.  Fractional units of months or less
+     are computed to be an integer number of days and seconds, assuming
+     24 hours per day.  For example, <literal>'1.5 months'</literal>
+     becomes <literal>1 month 15 days</literal>.

This entire passage is vague, and grammatically shaky too.  Perhaps
more like

      Fractional parts of units larger than months are rounded to the
      nearest integer number of months; for example '1.5 years'
      becomes '1 year 6 mons'.  Fractional parts of months are rounded
      to the nearest integer number of days, using the assumption that
      one month equals 30 days; for example '1.5 months'
      becomes '1 mon 15 days'.  Fractional parts of days and weeks
      are converted to microseconds, using the assumption that one day
      equals 24 hours.

      On output, the months field is shown as an appropriate number of
      years and months; the days field is shown as-is; the microseconds
      field is converted to hours, minutes, and possibly-fractional
      seconds.

			regards, tom lane





view thread (99+ messages)  latest in thread

Message-ID: <1008623.1627663774@sss.pgh.pa.us>
Permalink:  ../1008623.1627663774@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1008623.1627663774@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, bruce@momjian.us, dean.a.rasheed@gmail.com, wishdev@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Have I found an interval arithmetic bug?
  In-Reply-To: <1008623.1627663774@sss.pgh.pa.us>

* 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