↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

20000 — case_not_found

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.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Case Not Found
condition name
case_not_found
lang
en
sqlstate
20000

Definition PG 18

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.

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, P0001

Sources {#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.

Compare versions

SQLSTATE evidence and recorded runtime versions

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read the fixed errcodes definition row, severity, and macro.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "20000 is case_not_found in SQLSTATE Class 20."
}
claims · resolved-path
{
  "claim_id": "resolved-path",
  "limits": "This is source confirmation, not a runtime observation in this batch.",
  "method": "Read the complete source context around the resolved report group.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.pl_exec.case.18.6"
  ],
  "statement": "The fixed PostgreSQL 18.6 source contains the report path and message context described on the page."
}
claims · history-boundary
{
  "claim_id": "history-boundary",
  "limits": "Definition presence is not an emitting-path observation.",
  "method": "Compare canonical release-definition facts with the available history boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked release definitions establish catalogue presence from the known 8.4.0 boundary; they do not establish a precise introducing release or runtime use."
}
messages · message.case-not-found
{
  "limits": "",
  "message_id": "message.case-not-found",
  "path": "",
  "position": 0,
  "raw": {
    "hint_template": "CASE statement is missing ELSE part.",
    "id": "message.case-not-found",
    "primary_template": "case not found",
    "severity_source": "ERROR",
    "sources": [
      "src.pl_exec.case.18.6"
    ],
    "sqlstate": "20000"
  },
  "severity": "ERROR",
  "sources": [
    "src.pl_exec.case.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "case not found",
      "position": 0,
      "role": "",
      "template": "case not found"
    },
    {
      "kind": "hint",
      "literal": "CASE statement is missing ELSE part.",
      "position": 1,
      "role": "",
      "template": "CASE statement is missing ELSE part."
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L152"
}
sources · src.pl_exec.case.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/pl/plpgsql/src/pl_exec.c",
  "position": 1,
  "sha256": "0df3c70a6bccf6dddf443fb99e152a16a67009827c44a820597e98e585cb8b20",
  "source_id": "src.pl_exec.case.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/pl/plpgsql/src/pl_exec.c"
}
sources · src.calls.REL_18_6
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 2,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6",
  "tag": "",
  "url": ""
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:69e44a07bea95384686515d81c0953620adaaf44b2b39c94497c827c19a3af6e

Text language: en · english-manuals:69e44a07bea95384686515d81c0953620adaaf44b2b39c94497c827c19a3af6e