On Wednesday, May 6, 2026, PG Bug reporting form <
noreply@postgresql.org> wrote:
The following bug has been logged on the website:
Bug reference: 19472
Logged by: Pisces Mar.
Email address: vectorplanck@gmail.com
PostgreSQL version: 17.6
Operating system: x86_64-windows
Description:
Issue Description:
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).
Workaround:
Use parentheses: SELECT CAST((-32768) :: SMALLINT AS REAL);
Or use standard CAST syntax: SELECT CAST(-32768 AS SMALLINT);
These aren’t really workarounds; this is just how you need to write the expression given our long-established and not going to change operator precedence and literal syntax parsing rules.
David J.