integer out of range

SQLSTATE 22003 condition numeric_value_out_of_range class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

An arithmetic result or input value exceeds the range of a 32-bit integer (±2,147,483,647). PostgreSQL raises SQLSTATE 22003 (numeric_value_out_of_range).

What the server log shows

ERROR:  integer 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.”

integer is a signed 4-byte type. Any input or computed result outside its range cannot be represented, and PostgreSQL raises 22003 instead of wrapping around.

Common causes

How to fix it

  1. Migrate the column to bigint (and the sequence to bigint): ALTER TABLE t ALTER COLUMN id TYPE bigint;.
  2. Cast intermediate arithmetic to bigint to avoid overflow: sum(x::bigint).
  3. Use bigserial/bigint for surrogate keys from the start.

Related & next steps

Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.