SQLSTATE 22P02 ERROR Class 22: Data Exception

invalid_text_representation invalid input value for enum …: “…” — 22P02

PostgreSQL error "invalid input value for enum …: "…"" (SQLSTATE 22P02): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A value was supplied for an enum type that is not one of the type’s defined labels. PostgreSQL raises SQLSTATE 22P02 (invalid_text_representation).

  • The value is not a member of the enum.
  • Enum labels are case-sensitive and exact.
  • Common after adding a new state in code but not in the enum.

What the server log shows

ERROR:  invalid input value for enum order_status: "shipped"

Why PostgreSQL raises this — what the manual says

Section 8.7 Enumerated Types:

“Enum labels are case sensitive, so ‘happy’ is not the same as ‘HAPPY’.”

Enum values are constrained to a fixed label set. Input that is not one of those labels has no valid internal representation and is rejected with 22P02.

Common causes

  • A label that was never defined on the enum.
  • Wrong case or spelling of a label.
  • Application adding a new status not yet present in the enum type.

How to fix it

  1. Add the label: ALTER TYPE order_status ADD VALUE 'shipped';.
  2. Use an existing label with exact spelling/case.
  3. List labels: SELECT enum_range(NULL::order_status);.

Related & next steps

Reference: PostgreSQL 18 Section 8.7 “Enumerated Types”.

Was this helpful?