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

Re: INTEGER range ("-2147483648" is not accepted.)

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Satoshi Nagayasu <satoshi(dot)nagayasu(at)gmail(dot)com>
Cc: pgsql-docs <pgsql-docs(at)postgresql(dot)org>
Subject: Re: INTEGER range ("-2147483648" is not accepted.)
Date: 2010-06-22 08:44:42
Message-ID: AANLkTimwgKepmPoUE_JaBA-UsgXaXipNGVMUECUROYzA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-docs
On Tue, Jun 22, 2010 at 10:27 AM, Satoshi Nagayasu
<satoshi(dot)nagayasu(at)gmail(dot)com> wrote:
> Hi all,
>
> I've found a bit strange thing on the INTEGER range in the official manual.
>
> http://www.postgresql.org/docs/8.4/interactive/datatype-numeric.html
>
> According to the official manual, the INTEGER range is "-2147483648 to +2147483647".
> However, my example in below shows that "-2147483648" is not accepted.
>
> Is this correct? Any suggestions?
>
> template1=# SELECT -2147483648::integer;
> ERROR:  integer out of range

This gets parsed as "cast 2147483648 to integer, then take it
negative". Which overflows, because it can only go up to 2147483647.
What you want is:

postgres=# select (-2147483648)::integer;
    int4
-------------
 -2147483648
(1 row)


-- 
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

In response to

Responses

pgsql-docs by date

Next:From: Thom BrownDate: 2010-06-22 08:48:49
Subject: Re: INTEGER range ("-2147483648" is not accepted.)
Previous:From: Thom BrownDate: 2010-06-22 08:36:30
Subject: Re: INTEGER range ("-2147483648" is not accepted.)

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