20000 — case_not_found
20000
At a glance
SQLSTATE 20000 is raised by PL/pgSQL for a CASE statement that reaches no matching WHEN and has no ELSE. PostgreSQL 18.6 reports case not found with hint CASE statement is missing ELSE part. The condition is about the procedural CASE statement path; it is not the result of an ordinary query returning zero rows.
| Field | Value |
|---|---|
| SQLSTATE | 20000 |
| Condition | case_not_found |
| Status | active |
| Known present by | 8.4.0 |
| Locked snapshots | 9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3 |
| Macros | ERRCODE_CASE_NOT_FOUND |
| Aliases | — |
Meaning
The executor path is exec_stmt_case in src/pl/plpgsql/src/pl_exec.c. It evaluates the searched or simple procedural CASE statement and reports 20000 when control reaches the missing-ELSE branch. A SQL CASE expression has different semantics, so diagnose the statement form and routine source before changing a query.
Messages
The fixed message is case not found; the hint is CASE statement is missing ELSE part..
Diagnosis
Find the PL/pgSQL routine and the CASE statement named by the routine context. List the possible selector values or predicates and verify that every intended path has a WHEN; then check whether an ELSE was omitted. Do not use row-count checks or SELECT INTO STRICT diagnostics as a substitute for this condition.
Response
Add an ELSE branch that implements the intended fallback, or make the WHEN predicates exhaustive and verify the routine with representative selector values. If the missing case represents invalid business input, have the branch report the application-specific condition deliberately. After changing the routine, rerun the surrounding transaction only when its side effects were rolled back or the business operation is idempotent.
Versions
The locked catalogue places this condition at least by PostgreSQL 8.4.0. The release definitions cover the published snapshots listed in the facts block; source-path status is limited to the fixed PostgreSQL 18.6 context cited below.
Related
Sources
The fixed PL/pgSQL executor contains the message and hint. The PL/pgSQL CASE statement documentation describes the missing-ELSE behavior. See the structured evidence record for fixed source paths, scan scope, and unresolved runtime boundaries.