| From: | Bruce Momjian <bruce(at)momjian(dot)us> | 
|---|---|
| To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> | 
| Cc: | John W Higgins <wishdev(at)gmail(dot)com>, pgsql-hackers list <pgsql-hackers(at)lists(dot)postgresql(dot)org> | 
| Subject: | Re: Have I found an interval arithmetic bug? | 
| Date: | 2021-07-28 15:19:16 | 
| Message-ID: | 20210728151916.GA15440@momjian.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general pgsql-hackers | 
On Wed, Jul 28, 2021 at 08:42:31AM +0100, Dean Rasheed wrote:
> On Wed, 28 Jul 2021 at 00:08, John W Higgins <wishdev(at)gmail(dot)com> wrote:
> >
> > It's nice to envision all forms of fancy calculations. But the fact is that
> >
> > '1.5 month'::interval * 2 != '3 month"::interval
> >
> 
> That's not exactly true. Even without the patch:
> 
> SELECT '1.5 month'::interval * 2 AS product,
>        '3 month'::interval AS expected,
>        justify_interval('1.5 month'::interval * 2) AS justified_product,
>        '1.5 month'::interval * 2 = '3 month'::interval AS equal;
> 
>     product     | expected | justified_product | equal
> ----------------+----------+-------------------+-------
>  2 mons 30 days | 3 mons   | 3 mons            | t
> (1 row)
> 
> So it's equal even without calling justify_interval() on the result.
> 
> FWIW, I remain of the opinion that the interval literal code should
> just spill down to lower units in all cases, just like the
> multiplication and division code, so that the results are consistent
> (barring floating point rounding errors) and explainable.
Here is a more minimal patch that doesn't change the spill-down units at
all, but merely documents it, and changes the spilldown to months to
round instead of truncate.
-- 
  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.
| Attachment | Content-Type | Size | 
|---|---|---|
| interval.diff | text/x-diff | 5.2 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2021-07-28 15:31:08 | Re: Have I found an interval arithmetic bug? | 
| Previous Message | Adrian Klaver | 2021-07-28 15:18:48 | Re: PostgreSQL reference coffee mug | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bharath Rupireddy | 2021-07-28 15:25:27 | Re: when the startup process doesn't (logging startup delays) | 
| Previous Message | Tony Zhu | 2021-07-28 15:09:07 | Re: [Proposal] Global temporary tables |