Re: Type and CAST error on lowest negative integer values for smallint, int and bigint - Mailing list pgsql-hackers

From David Rowley
Subject Re: Type and CAST error on lowest negative integer values for smallint, int and bigint
Date
Msg-id CAApHDvq0iECqPDrbjyBPJAiywPmdWSAM-ppBtnNOpoL3_=SjWQ@mail.gmail.com
Whole thread Raw
In response to Type and CAST error on lowest negative integer values for smallint, int and bigint  (Hans Buschmann <buschmann@nidsa.net>)
Responses AW: Type and CAST error on lowest negative integer values for smallint, int and bigint
List pgsql-hackers
On Thu, 2 May 2024 at 23:25, Hans Buschmann <buschmann@nidsa.net> wrote:
> postgres=# select -32768::smallint;
> ERROR:  smallint out of range

The precedence order of operations applies the cast before the unary
minus operator.

Any of the following will work:

postgres=# select cast(-32768 as smallint), (-32768)::smallint,
'-32768'::smallint;
  int2  |  int2  |  int2
--------+--------+--------
 -32768 | -32768 | -32768
(1 row)

David



pgsql-hackers by date:

Previous
From: Hans Buschmann
Date:
Subject: Type and CAST error on lowest negative integer values for smallint, int and bigint
Next
From: Alexander Lakhin
Date:
Subject: Re: Typos in the code and README