百科 / 错误代码 / Class P0 PL/pgSQL错误
P0002 no_data_found
ERROR 源码确认 参考 未实测
- 条件名
no_data_found- 宏名称
ERRCODE_NO_DATA_FOUND- 启用版本
- 8.2
- 状态
- 活跃
版本覆盖
速览
P0002 是 PL/pgSQL 专用的 no_data_found。固定源码确认它既有 PL/pgSQL 查询契约中的 ERROR,也有核心 tablespace 路径中的 NOTICE;不能把它等同于所有返回零行的 SELECT。
含义
在 PL/pgSQL 固定路径中,受检查的查询没有返回行时会报告 query returned no rows,若启用 strict 参数打印还会附带 parameters: %s detail。另一个固定路径在 tablespace 没有匹配 relation 时以 NOTICE 使用同一 SQLSTATE。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
no matching relations in tablespace "%s" found
诊断
先确认完整 message 和 severity,再定位操作。PL/pgSQL 路径要检查目标赋值、严格单行契约和 print_strict_params;tablespace NOTICE 则检查目标 tablespace 与匹配 relation。普通查询返回零行本身不会自动等于 P0002。
处置
对 PL/pgSQL 严格查询,修正查询预期、目标赋值或显式处理无行分支;也可以在明确业务允许时改用不要求单行的逻辑。对 tablespace NOTICE,先核对没有匹配 relation 是否符合预期;如果这是正常结果,无需修复,否则再修正目标后继续。不要仅因零行就自动重试。
版本
锁定目录从 8.2.0 记录该条件,并在列出的正式快照及 19beta3 中出现;固定源码还显示它可以是 ERROR 或 NOTICE。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 492 行
- 上游源码 src/pl/plpgsql/src/pl_exec.c 第 4384–4387 行
- 上游源码 src/backend/commands/tablecmds.c 第 17162–17166 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
P0002 is no_data_found in PostgreSQL-specific Class P0.
-
PL/pgSQL fixed paths report P0002 with `query returned no rows` when the checked query produced no row; optional detail is `parameters: %s` when strict-parameter printing is enabled.
-
A core tablespace path also uses P0002 at NOTICE level for no matching relations in a tablespace.
-
P0002 is not a synonym for every SELECT that happens to return zero rows; the operation and enforcing path determine whether it is raised.
同类错误代码
Class P0 PL/pgSQL错误 下的其他成员。