Re: Fix overflow in justify_interval related functions

Поиск
Список
Период
Сортировка
От Joseph Koshakow
Тема Re: Fix overflow in justify_interval related functions
Дата
Msg-id CAAvxfHceWFDCTGqzjuRgYa46SPAKJViHosXZ1dqYLmtnpzqnLw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Fix overflow in justify_interval related functions  (Nathan Bossart <nathandbossart@gmail.com>)
Ответы Re: Fix overflow in justify_interval related functions  (Joseph Koshakow <koshy44@gmail.com>)
Re: Fix overflow in justify_interval related functions  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
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

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ranier Vilela
Дата:
Сообщение: Re: Postgres 14.2 Windows can't rename temporary statistics file
Следующее
От: Joseph Koshakow
Дата:
Сообщение: Re: Fix overflow in DecodeInterval