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

From: Hans Buschmann <buschmann(at)nidsa(dot)net>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Type and CAST error on lowest negative integer values for smallint, int and bigint
Date: 2024-05-02 11:25:32
Message-ID: 5795b386f0644faf92aa63de3694923b@nidsa.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I tried to initialize a table with values for smallint columns.

The final goal is to get mask values for logical operations.

The insert failed with ERROR: smallint out of range.

the same occurs when using a simple select statement like:

select -32768::smallint;
select -2147483648::int;
select -9223372036854775808::bigint;

These limit values are taken from the documentation 8.1.1 Integer Types

This occurs on PG16.2 on Windows or Linux (64bit).

This prevents me to enter the binary value 0b10000000_00000000 into a smallint column
(I could use some other tricks, but this is ugly!)

-----------

postgres=# select version ();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0), 64-bit
(1 Zeile)

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

Thank you for looking

Hans Buschmann

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2024-05-02 11:33:55 Re: Type and CAST error on lowest negative integer values for smallint, int and bigint
Previous Message Jelte Fennema-Nio 2024-05-02 11:11:44 Re: Reducing the log spam