Re: Have I found an interval arithmetic bug?

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Zhihong Yu <zyu(at)yugabyte(dot)com>
Cc: John W Higgins <wishdev(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Have I found an interval arithmetic bug?
Date: 2021-04-03 02:19:05
Message-ID: 20210403021905.GF29126@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Fri, Apr 2, 2021 at 06:11:08PM -0700, Zhihong Yu wrote:
> Hi,
> I got a local build with second patch where:
>
> yugabyte=# SELECT  interval '0.3 years' + interval '0.4 years' -
>                 interval '0.7 years';
>  ?column?
> ----------
>  1 mon
>
> I think the outcome is a bit unintuitive (I would expect result close to 0).

Uh, the current code returns:

SELECT interval '0.3 years' + interval '0.4 years' - interval '0.7 years';
?column?
----------
-1 mon

and with the patch it is:

SELECT interval '0.3 years' + interval '0.4 years' - interval '0.7 years';
?column?
----------
1 mon

What it isn't, is zero months, which is the obviously ideal answer.

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

If only the physical world exists, free will is an illusion.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2021-04-03 02:21:26 Re: Have I found an interval arithmetic bug?
Previous Message Stacey Haysler 2021-04-03 02:07:52 Fwd: Proposed Italian Translation of Code of Conduct Policy

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2021-04-03 02:21:26 Re: Have I found an interval arithmetic bug?
Previous Message Zhihong Yu 2021-04-03 02:06:08 Re: Have I found an interval arithmetic bug?