# 20000 — case_not_found

> Source-backed reference for PostgreSQL SQLSTATE 20000.
---

# 20000

## At a glance {#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.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| 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 | `—` |

<!-- source facts: data/errcodes/20000.json -->
<!-- END SQLSTATE FACTS -->

## Meaning {#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 {#messages}

The fixed message is `case not found`; the hint is `CASE statement is missing ELSE part.`.

## Diagnosis {#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 {#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 {#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 {#related}

[`02000`](../02000/), [`P0001`](../p0001/)

## Sources {#sources}

The fixed [PL/pgSQL executor](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/pl/plpgsql/src/pl_exec.c#L2627-L2630) contains the message and hint. The [PL/pgSQL CASE statement documentation](https://www.postgresql.org/docs/18/plpgsql-control-structures.html#PLPGSQL-CONDITIONALS) describes the missing-ELSE behavior. See the structured [evidence record](../data/evidence/20000.json) for fixed source paths, scan scope, and unresolved runtime boundaries.
