SQLSTATE 22003Severity lowLab verified

Incident brief

Numeric value out of range

A value didn't fit in the numeric type's allowed range. PostgreSQL rejects it instead of wrapping it around or silently rounding it.

What lands in your log

ERROR: smallint out of range

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
Create a table with a smallint column.
Fix
Use a wider integer type (integer or bigint) if values can legitimately exceed smallint's range.
Proof
Reproduced on PostgreSQL 16.14 → Inserting 40000 into a smallint column (documented range -32768 to +32767) was rejected with SQLSTATE 22003. No row was stored.

Fix

What to do right now

Application-level steps for this error.

  • Use a wider integer type (integer or bigint) if values can legitimately exceed smallint's range.
  • Validate expected value ranges in the application before inserting.
  • Remember arithmetic on in-range values can still overflow the result type, see the premium counterexample below.
Fix SQL
-- widen the type so a legitimately larger value fits
ALTER TABLE metrics.counters ALTER COLUMN count TYPE integer;
INSERT INTO metrics.counters (id, count) VALUES (5, 40000);

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops