Skip site navigation (1) Skip section navigation (2)

Re: Integer parsing bug?

From: Steve Atkins <steve(at)blighty(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Integer parsing bug?
Date: 2004-03-03 23:34:47
Message-ID: 20040303233446.GC25314@gp.word-to-the-wise.com (view raw or flat)
Thread:
Lists: pgsql-bugs
On Wed, Mar 03, 2004 at 06:27:07PM -0500, Tom Lane wrote:
> 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;

OK... That makes sense if the parser has no support for negative
constants, but it doesn't seem like intuitive behaviour.


BTW, the original issue that led to this was:

db=>CREATE function t(integer) RETURNS integer AS '
BEGIN
  return 0;
END;
' LANGUAGE 'plpgsql';

db=> select t(-2147483648);
ERROR:  function t(bigint) does not exist

Which again makes sense considering the way the parser works, but
still seems to violate the principle of least surprise.

Cheers,
  Steve


In response to

pgsql-bugs by date

Next:From: PostgreSQL Bugs ListDate: 2004-03-04 02:08:47
Subject: BUG #1091: Localization in EUC_TW Can't decode Big5 0xFA40--0xFEF0.
Previous:From: Tom LaneDate: 2004-03-03 23:27:07
Subject: Re: Integer parsing bug?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group