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