Re: Fix overflow in justify_interval related functions

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Joseph Koshakow <koshy44(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Fix overflow in justify_interval related functions
Date: 2022-02-15 00:59:18
Message-ID: 20220215005918.GA2186095@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Feb 14, 2022 at 04:57:07PM -0500, Joseph Koshakow wrote:
> On Mon, Feb 14, 2022 at 2:15 PM Nathan Bossart <nathandbossart(at)gmail(dot)com> wrote:
>> Makes sense. So we could likely avoid it for justify_interval, but the
>> others are at the mercy of the interval implementation.
>
> I'm not entirely sure what you mean by "it", but for both
> justify_interval and justify_days this commit throws an error if we
> try to set the months field above 2^31.
>
>> +SELECT justify_days(interval '2147483647 months 30 days');
>> +ERROR: interval out of range
>> +SELECT justify_interval(interval '2147483647 months 30 days');
>> +ERROR: interval out of range
>
> That's what these are testing.

I think it's possible to avoid overflow in justify_interval() in some cases
by pre-justifying the days. I've attached a patch to demonstrate.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v2-0001-Check-for-overflow-in-justify_interval-functions.patch text/x-diff 6.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2022-02-15 01:08:56 Re: Postgres 14.2 Windows can't rename temporary statistics file
Previous Message Bruce Momjian 2022-02-15 00:58:22 Re: support for CREATE MODULE