Re: Type and CAST error on lowest negative integer values for smallint, int and bigint

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Hans Buschmann <buschmann(at)nidsa(dot)net>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Type and CAST error on lowest negative integer values for smallint, int and bigint
Date: 2024-05-02 11:33:55
Message-ID: CAApHDvq0iECqPDrbjyBPJAiywPmdWSAM-ppBtnNOpoL3_=SjWQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 2 May 2024 at 23:25, Hans Buschmann <buschmann(at)nidsa(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Lakhin 2024-05-02 12:00:00 Re: Typos in the code and README
Previous Message Hans Buschmann 2024-05-02 11:25:32 Type and CAST error on lowest negative integer values for smallint, int and bigint