Re: BUG #15071: Error in PostgreSQL-specific :: type cast

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: whiteman(dot)kr(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15071: Error in PostgreSQL-specific :: type cast
Date: 2018-02-16 15:31:44
Message-ID: CA+bJJbxJuBag4+gW+nTJkuL=-ic+8fO5kdcip3KeEL-nBQ5K5A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Feb 16, 2018 at 12:57 PM, PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:

...
> SELECT -32768::smallint
> ^ERROR: smallint out of range

This is interpreted as -(32768::smallint)

...
> Standard-syntax type casts are workes correctly:
> SELECT cast(-32768 as smallint)

This is not.

When in doubt, put parenthesis

postgres=# select (-32768)::smallint;
int2
--------
-32768
(1 row)

postgres=# select -(32768::smallint);
ERROR: smallint out of range
postgres=# select -32768::smallint;
ERROR: smallint out of range

And IIRC, expression with implicit casts ( like when comparing
constnat to columns) work because they use the conversion from
text/unknown...

postgres=# select '-32768'::smallint;
int2
--------
-32768
(1 row)

Francisco Olarte.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bradley Ayers 2018-02-17 22:54:19 Transaction local custom settings set to '' rather than removed entirely after transaction ends
Previous Message Tom Lane 2018-02-16 15:29:23 Re: BUG #15071: Error in PostgreSQL-specific :: type cast