PostgreSQL error 22003 (Numeric Value Out of Range) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
Inspect the column type and its precision/scale. If that does not apply, use a wider numeric type or numeric without fixed precision — the full checklist is below.
SQLSTATE: 22003
Official name: Numeric Value Out of Range
Service: PostgreSQL
A numeric value is out of the range allowed by the column type or operation.
SELECT CASE WHEN b = 0 THEN NULL ELSE a / b END FROM t;
Pairing range guards prevents numeric overflow/underflow during arithmetic that would otherwise raise 22003.
Use Numeric(precision=None) for arbitrary-precision, or validate ranges in Python.
price = Column(Numeric) # arbitrary precision
Use models.DecimalField with adequate max_digits/decimal_places.
price = models.DecimalField(max_digits=19, decimal_places=4)
Most often this happens when storing a value larger than the declared precision/scale of numeric(p,s), or when an integer value exceeding smallint/integer/bigint limits.
Inspect the column type and its precision/scale.
This page documents fixes for: sqlalchemy, django.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.