SQLSTATE 22P02Severity mediumLab verified

Incident brief

Invalid input syntax

A string literal was cast to a type whose input function couldn't parse it. PostgreSQL rejected the value outright rather than guessing at a conversion.

What lands in your log

ERROR: invalid input syntax for type integer: "not_a_number"

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

In 10 seconds

What triggers it
Cast a string literal to a type whose input function can't parse it (e.g. a non-numeric string to integer).
Fix
Fix the literal so it matches the target type's actual input format.
Proof
Reproduced on PostgreSQL 16.14 → Casting a non-numeric string to integer was rejected with SQLSTATE 22P02, naming the exact invalid value. The session was unaffected afterward.

Fix

What to do right now

Application-level steps for this error.

  • Fix the literal so it matches the target type's actual input format.
  • For boolean specifically, only a documented set of strings, and their unique prefixes, are accepted; see the premium test.
  • Don't rely on NULLIF to guard this generally, see the counterexample for why it only catches one specific value.
Fix SQL
SELECT '42'::integer;

Verification

PG 16.14
Last verified
2026-07-15 (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