20000 — case_not_found
PL/pgSQL 的 CASE 无匹配分支且缺少 ELSE。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Case Not Found
- condition name
- case_not_found
- lang
- en
- sqlstate
- 20000
版本定义 PG 18
20000
速览 {#at-a-glance}
SQLSTATE 20000 在 PL/pgSQL 的 CASE 语句没有匹配任何 WHEN 且没有 ELSE 时报告。PostgreSQL 18.6 的消息是 case not found,hint 为 CASE statement is missing ELSE part.。该条件属于过程式 CASE 语句路径,不是普通查询返回零行的结果。
含义 {#meaning}
执行器路径位于 src/pl/plpgsql/src/pl_exec.c 的 exec_stmt_case。它执行搜索式或简单过程式 CASE 语句,在到达缺失 ELSE 的分支时报告 20000。SQL CASE 表达式语义不同,因此应先确认语句形式和例程源码,再修改查询。
消息 {#messages}
固定消息是 case not found;hint 为 CASE statement is missing ELSE part.。
诊断 {#diagnosis}
找到 routine context 指出的 PL/pgSQL 例程和 CASE 语句。列出选择值或谓词的可能结果,确认每个预期路径都有 WHEN,再检查是否遗漏 ELSE。不要用行数检查或 SELECT INTO STRICT 的诊断替代这个条件。
处理 {#response}
增加实现预期回退行为的 ELSE 分支,或使 WHEN 谓词覆盖所有可能值,并用代表性选择值验证例程。如果缺失分支代表无效业务输入,应由该分支有意报告应用条件。修改例程后,只有确认周围事务的副作用已回滚或业务操作具备幂等性时,才重新执行事务。
版本 {#versions}
锁定目录将该条件的已知下界记为 PostgreSQL 8.4.0。事实块列出已发布快照;源码路径状态仅限于下方固定的 PostgreSQL 18.6 资料。
相关 {#related}
来源 {#sources}
固定的 PL/pgSQL 执行器包含消息和 hint。PL/pgSQL CASE 语句文档说明缺少 ELSE 时的行为。 详见结构化证据记录,其中记录固定源码路径、扫描范围和未解决的运行边界。
比较版本
SQLSTATE 证据与已记录的运行版本
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": ""
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:69e44a07bea95384686515d81c0953620adaaf44b2b39c94497c827c19a3af6e
正文语言: zh-Hans · english-manuals:69e44a07bea95384686515d81c0953620adaaf44b2b39c94497c827c19a3af6e