Re: Remove dependence on integer wrapping

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Joseph Koshakow <koshy44(at)gmail(dot)com>
Cc: Matthew Kim <matthewkmkim(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Remove dependence on integer wrapping
Date: 2024-08-12 10:33:13
Message-ID: CACJufxFUKTQx8wUpxtRPT31D+a7fNxAL_A_-S4XaR-oZkKEgxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Aug 10, 2024 at 11:41 PM Joseph Koshakow <koshy44(at)gmail(dot)com> wrote:
>
>
>
> On Thu, Aug 8, 2024 at 9:01 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
> >
> > Should the error about integers be out of range?
> >
> > SELECT make_date(-2147483648, 1, 1);
> > "-2147483648" is not an allowed integer.
> >
> > \df make_date
> > List of functions
> > Schema | Name | Result data type | Argument data
> > types | Type
> > ------------+-----------+------------------+------------------------------------------+------
> > pg_catalog | make_date | date | year integer, month
> > integer, day integer | func
>
> Are you saying that with the patch applied you're seeing the above
> error? If so, I see a different error.
>
> test=# SELECT make_date(-2147483648, 1, 1);
> ERROR: date field value out of range
>
> Or are you saying that we should change the code in the patch so that
> it returns the above error? If so, I'm not sure I understand the
> reasoning. -2147483648 is an allowed integer, it's the minimum allowed
> value for integers.
>
> test=# SELECT (-2147483648)::integer;
> int4
> -------------
> -2147483648
> (1 row)
>

sorry, i mixed up
select (-2147483648)::int;
with
select -2147483648::int;

looks good to me.
maybe make it more explicit:
errmsg("date field (year) value out of range")));
i don't have a huge opinion though.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2024-08-12 10:35:44 Re: Historic snapshot doesn't track txns committed in BUILDING_SNAPSHOT state
Previous Message David Rowley 2024-08-12 10:32:22 Re: minor comments issue in ResultRelInfo src/include/nodes/execnodes.h