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
numericto bigint.
How to fix it
- Use
numericfor values beyond 64-bit range. - Cast operands to
numericbefore arithmetic to avoid overflow. - Validate magnitudes before storing as bigint.
Related & next steps
Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.
Thanks — noted. This helps keep the database accurate.