On Mon, Feb 14, 2022 at 11:23 PM Nathan Bossart
<nathandbossart@gmail.com> wrote:
> It's a little weird
> that justify_hours() and justify_days() can overflow in cases where there
> is still a valid interval representation, but as Tom noted, those functions
> have specific charters to follow.
Yes it is a bit weird, but this follows the same behavior as adding
Intervals. The following query overflows:
postgres=# SELECT interval '2147483647 days' + interval '1 day';
ERROR: interval out of range
Even though the following query does not:
postgres=# SELECT justify_days(interval '2147483647 days') + interval '1 day';
?column?
-----------------------------
5965232 years 4 mons 8 days
(1 row)
The reason is, as Tom mentioned, that Interval's months, days, and
time (microseconds) are stored separately. They are only combined
during certain scenarios such as testing for equality, ordering,
justify_* methods, etc. I think the idea behind it is that not every month
has 30 days and not every day has 24 hrs, though I'm not sure
.
> > + ereport(ERROR,
> > + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
> > + errmsg("interval out of range")));
>
> nitpick: I think there is ordinarily an extra space before errmsg() so that
> it lines up with errcode().
I've attached a patch to add the space. Thanks so much for your review
and comments!
- Joe Koshakow