SQLSTATE 22003 ERROR Class 22: Data Exception

numeric_value_out_of_range bigint out of range — 22003

PostgreSQL error "bigint 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 bigint (±9.2×10^18). PostgreSQL raises SQLSTATE 22003 (numeric_value_out_of_range).

  • Arithmetic result is beyond bigint’s 64-bit range.
  • Common with large multiplications or sums.
  • Casting a wider numeric into bigint can trigger it.

What the server log shows

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

bigint is a signed 64-bit integer. A value or result outside its range cannot be represented, so PostgreSQL reports 22003 rather than wrapping.

Common causes

  • Multiplying large bigints together.
  • Summing many large values into a bigint.
  • Casting an out-of-range numeric to bigint.

How to fix it

  1. Use numeric for values beyond 64-bit range.
  2. Cast operands to numeric before arithmetic to avoid overflow.
  3. Validate magnitudes before storing as bigint.

Related & next steps

Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.

Keep going

Related & next steps

Was this helpful?