SQLSTATE 22003 ERROR Class 22: Data Exception

numeric_value_out_of_range smallint out of range — 22003

PostgreSQL error "smallint out of range" (SQLSTATE 22003): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A value or computation exceeded the range of smallint (-32768 to 32767). PostgreSQL raises SQLSTATE 22003 (numeric_value_out_of_range).

  • Result is beyond smallint’s 16-bit range.
  • Common when inserting larger numbers into a smallint column.
  • Casting a larger integer to smallint can trigger it.

What the server log shows

ERROR:  smallint out of range

Why PostgreSQL raises this — what the manual says

Section 8.1.1 Integer Types:

“Attempts to store values outside of the allowed range will result in an error.”

smallint is a signed 16-bit integer. A value outside its narrow range cannot be represented and PostgreSQL reports 22003.

Common causes

  • Inserting a value larger than 32767 into a smallint column.
  • Arithmetic overflowing the 16-bit range.
  • An undersized column type for the data.

How to fix it

  1. Use integer or bigint for larger values.
  2. Change the column type if the data outgrew smallint.
  3. Validate input ranges before insert.

Related & next steps

Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.

Was this helpful?