Re: BUG #16247: Cast error on integer

From: Andres Freund <andres(at)anarazel(dot)de>
To: ddtripathy(at)yahoo(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16247: Cast error on integer
Date: 2020-02-06 22:12:48
Message-ID: 20200206221248.stef4pssng3h466z@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

On 2020-02-06 21:43:41 +0000, PG Bug reporting form wrote:
> The only difference between the two calls is how I'm casting the integer.
> The second call is choking on "_devctrluid => -2147483648::int". But, if I
> change that value to "-2147483647" the second call succeeds.

I don't think that's a bug. -2147483648::int is parsed as
-((2147483648)::int). 2147483648 gets parsed as an int8 (due to its
width), but then you're casting the result to an int4. And 2147483648 is
not representable as a signed 32bit integer. It fails before getting to
negating the result of the cast.

For precedence see:
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE-TABLE

Whereas '-2147483648'::int4 gets read directly as int4, including the
sign. And wheras 2147483648 is not representable as an int4, -2147483648
is.

Greetings,

Andres Freund

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2020-02-06 22:30:15 Re: FK violation in partitioned table after truncating a referenced partition
Previous Message Alvaro Herrera 2020-02-06 22:05:25 Re: FK violation in partitioned table after truncating a referenced partition