Diagnostic Queries
Symptoms
A textual value was too large (or small) to fit a bigint during conversion. PostgreSQL raises SQLSTATE 22003 (numeric_value_out_of_range).
- The value exceeds the 64-bit bigint range.
- Common parsing huge numeric strings.
- bigint spans roughly ±9.2×10^18.
What the server log shows
ERROR: value "9999999999999999999999" is out of range for type bigint
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. Converting a value beyond its range cannot be represented, so PostgreSQL reports 22003.
Common causes
- Parsing a numeric string larger than 64 bits.
- Arithmetic/aggregation overflowing bigint.
- Choosing bigint where
numericis needed for huge values.
How to fix it
- Use
numericfor arbitrarily large integers. - Validate inputs against the bigint range before conversion.
- Cast intermediate results to
numericto avoid overflow.
Related & next steps
Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.
Thanks — noted. This helps keep the database accurate.