PostgreSQL Error 22003: Numeric Value Out of Range

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.

SQLSTATE 22003 PostgreSQL Last verified 2026-08-19

Quick Answer

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.

Error Code

SQLSTATE: 22003
Official name: Numeric Value Out of Range
Service: PostgreSQL

What does this error mean?

A numeric value is out of the range allowed by the column type or operation.

Common Causes

How to Fix

  1. Inspect the column type and its precision/scale
  2. Use a wider numeric type or numeric without fixed precision
  3. Clamp or validate the value at the application layer
  4. Handle arithmetic overflow with CASE/NULLIF guards

Code Examples

Guard against division overflow sql
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.

Framework-Specific Fixes

sqlalchemy

Use Numeric(precision=None) for arbitrary-precision, or validate ranges in Python.

price = Column(Numeric)  # arbitrary precision
django

Use models.DecimalField with adequate max_digits/decimal_places.

price = models.DecimalField(max_digits=19, decimal_places=4)

You Might Also Like

Frequently Asked Questions

Why am I seeing PostgreSQL error 22003?

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.

How do I fix PostgreSQL error 22003?

Inspect the column type and its precision/scale.

Which frameworks have documented fixes for error 22003?

This page documents fixes for: sqlalchemy, django.

Official Sources

This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.