Re: SELECT x'00000000F'::int leading zeros causes "integer out of range"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, Chris Lexvold <lexvold(at)telsasoft(dot)com>
Subject: Re: SELECT x'00000000F'::int leading zeros causes "integer out of range"
Date: 2017-02-24 19:13:06
Message-ID: 9486.1487963586@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Justin Pryzby <pryzby(at)telsasoft(dot)com> writes:
> Is this expected behavior ?
> ts=# SELECT x'00000000F'::int;
> ERROR: 22003: integer out of range
> LOCATION: bittoint4, varbit.c:1575

Yes. The provided operation is "convert a bitstring of up to 32 bits
to an integer". It's not "guess whether it's okay to throw away some
bits to make an integer".

As an example, even if you think it's obvious that it would be okay
to convert that bitstring to "15", would it be all right to convert
x'FFFFFFFFF' to "-1" ?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Melvin Davidson 2017-02-24 19:17:15 Re: SELECT x'00000000F'::int leading zeros causes "integer out of range"
Previous Message Justin Pryzby 2017-02-24 19:02:48 SELECT x'00000000F'::int leading zeros causes "integer out of range"