Re: Have I found an interval arithmetic bug?

From: John W Higgins <wishdev(at)gmail(dot)com>
To: pgsql-hackers list <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Have I found an interval arithmetic bug?
Date: 2021-07-27 23:08:22
Message-ID: CAPhAwGyccJZT-mXzHU1216Q-Z_xY3q+4TixzZ2sZf3hiPFe5tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Jul 27, 2021 at 3:36 PM Bryn Llewellyn <bryn(at)yugabyte(dot)com> wrote:

>
> with
> c1 as (
> select
> '1 month 1 day 1 second'::interval as i1,
> '1.234 month 1.234 day 1.234 second'::interval as i3),
>
> c2 as (
> select i1*1.234 as i2, i3 from c1)
>
> select i2::text as i2_txt, i3::text from c2 as i3_txt;
>
>
It's nice to envision all forms of fancy calculations. But the fact is that

'1.5 month'::interval * 2 != '3 month"::interval

with any of these patches - and if that doesn't work - the rest of the
strange numbers really seem to be irrelevant.

If there is a desire to handle fractional cases - then all pieces need to
be held as provided until they are transformed into something. In other
words - 1.5 month needs to be held as 1.5 month until we ask for it to be
reduced to 1 month and 15 days at some point. If the interval data type
immediately casts 1.5 months to 1 month 15 days then all subsequent
calculations are going to be wrong.

I appreciate there is generally no way to accomplish this right now - but
that means walking away from things like 1 month * 1.234 as being not
calculable as opposed to trying to piece something together that fails
pretty quickly.

John

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message obi reddy 2021-07-28 05:40:01 I need another option.
Previous Message Bryn Llewellyn 2021-07-27 22:36:37 Re: Have I found an interval arithmetic bug?

Browse pgsql-hackers by date

  From Date Subject
Next Message Bossart, Nathan 2021-07-27 23:29:28 Re: Out-of-memory error reports in libpq
Previous Message Tom Lane 2021-07-27 22:40:48 Out-of-memory error reports in libpq