Re: Integer parsing bug?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steve Atkins <steve(at)blighty(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Subject: Re: Integer parsing bug?
Date: 2004-03-03 23:27:07
Message-ID: 19111.1078356427@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Steve Atkins <steve(at)blighty(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Steve Atkins 2004-03-03 23:34:47 Re: Integer parsing bug?
Previous Message Suresh Babu.A.G 2004-03-03 20:23:39 Re: BUG #1090: initdb does not work