Re: Extract epoch from Interval weird behavior

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Joseph Koshakow <koshy44(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Extract epoch from Interval weird behavior
Date: 2022-04-19 19:12:52
Message-ID: 118d5351-4d7e-8b35-8837-9139a9cc7bd3@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 08.04.22 15:10, Tom Lane wrote:
> Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> writes:
>> We really wanted to avoid doing calculations in numeric as much as
>> possible. So we should figure out a different way to write this. The
>> attached patch works for me. It's a bit ugly since it hardcodes some
>> factors. Maybe we can rephrase it a bit more elegantly.
>
> I think it's fine but needs some commentary. Maybe about like
> "To do this calculation in integer arithmetic even though
> DAYS_PER_YEAR is fractional, multiply everything by 4
> and then divide by 4 again at the end. This relies on
> DAYS_PER_YEAR being a multiple of 0.25 and on SECS_PER_DAY
> being a multiple of 4."
>
> BTW, it might be good to parenthesize as
>
> (... big calculation ...) * (SECS_PER_DAY/4)
>
> to eliminate any question of whether the value could overflow
> before the final division by 4.

done that way

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2022-04-19 19:14:46 Re: Readd use of TAP subtests
Previous Message Jacob Champion 2022-04-19 19:07:35 Re: Readd use of TAP subtests