Re: lower integer bound not supported

From: Sandro Santilli <strk(at)kbt(dot)io>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: lower integer bound not supported
Date: 2016-06-08 16:43:19
Message-ID: 20160608164319.GA5590@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Jun 08, 2016 at 12:37:59PM -0400, Alvaro Herrera wrote:
> Sandro Santilli wrote:
> > According to documentation (from 9.1 to 9.5) the supported
> > integer ranges are these ones:
> >
> > smallint 2 bytes -32768 to +32767
> > integer 4 bytes -2147483648 to +2147483647
> > bigint 8 bytes -9223372036854775808 to +9223372036854775807
> >
> > But the lowest bound is not really supported:
> >
> > # select -32768::int2;
> > ERROR: smallint out of range
> > # select -2147483648::int4;
> > ERROR: integer out of range
> > # select -9223372036854775808::int8;
> > ERROR: bigint out of range
>
> This is reported every once in a while. It's not a bug, just an
> operator precedence issue: the :: binds more tightly than the unary - so
> the number is interpreted as a positive value first, which is indeed out
> of range. Try "(-32768)::int2".

That explains!

> Maybe it would be clearer if the error message indicated what's the
> value that's out of range, so that the lack of the minus might make the
> problem more evident; and perhaps add a HINT suggesting to add the
> parens?

An HINT suggesting parens would be very very helpful.

--strk;

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Eric Worden 2016-06-08 19:11:32 Fwd: BUG #14181: pg_upgrade: operator family "btree_hstore_ops" does not exist
Previous Message Alvaro Herrera 2016-06-08 16:37:59 Re: lower integer bound not supported