public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: [email protected]
To: [email protected]
Subject: Re: BUG #19472: CAST(-32768::SMALLINT AS REAL) fails with "SMALLINT out of range" but -32768 is valid SMALLINT value
Date: Wed, 06 May 2026 14:53:34 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On Wed, 2026-05-06 at 09:09 +0000, PG Bug reporting form wrote:
> When casting -32768 to SMALLINT and then to REAL using the :: operator,
> PostgreSQL throws an error "smallint out of range", even though -32768 is a
> valid value within the SMALLINT range (-32768 to +32767).
> 
> Expected Behavior:
> -32768 should be recognized as a valid SMALLINT value (the minimum value for
> smallint is -32768), and the cast to REAL should succeed.

This is not a bug, but working as expected.
The documentation at https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE
clearly states that the typecast operator :: has higher precedence than
an unary minus.

Yours,
Laurenz Albe






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: BUG #19472: CAST(-32768::SMALLINT AS REAL) fails with "SMALLINT out of range" but -32768 is valid SMALLINT value
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox