On Wed, Mar 03, 2004 at 06:27:07PM -0500, Tom Lane wrote:
> Steve Atkins <[EMAIL PROTECTED]> 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


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to