Re: Integer parsing bug? - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Integer parsing bug?
Date
Msg-id 19111.1078356427@sss.pgh.pa.us
Whole thread Raw
In response to Re: Integer parsing bug?  (Steve Atkins <steve@blighty.com>)
Responses Re: Integer parsing bug?
List pgsql-bugs
Steve Atkins <steve@blighty.com> writes:
>> test=> select -2147483648::int;
>> ERROR:  integer out of range

There is no bug here.  You are mistakenly assuming that the above
represents
    select (-2147483648)::int;
But actually the :: operator binds more tightly than unary minus,
so Postgres reads it as
    select -(2147483648::int);
and quite rightly fails to convert the int8 literal to int.

If you write it with the correct parenthesization it works:

regression=# select -2147483648::int;
ERROR:  integer out of range
regression=# select (-2147483648)::int;
    int4
-------------
 -2147483648
(1 row)


            regards, tom lane

pgsql-bugs by date:

Previous
From: "Suresh Babu.A.G"
Date:
Subject: Re: BUG #1090: initdb does not work
Next
From: Steve Atkins
Date:
Subject: Re: Integer parsing bug?