百科 / 错误代码 / Class P0 PL/pgSQL错误
P0003 too_many_rows
ERROR 源码确认 参考 未实测
- 条件名
too_many_rows- 宏名称
ERRCODE_TOO_MANY_ROWS- 启用版本
- 8.2
- 状态
- 活跃
版本覆盖
速览
P0003 是 PL/pgSQL too_many_rows。固定路径给出准确的 message、可选 detail、hint 和按实际分支决定的严重级别。
含义
当受检查的 PL/pgSQL 查询返回多于一行时,源码报告 query returned more than one row;开启 strict 参数打印时可附带 parameters: %s,并在一条路径提供 Make sure the query returns a single row, or use LIMIT 1. hint。普通多行 SELECT 不会因此自动成为 P0003。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
query returned more than one row
parameters: %s
Make sure the query returns a single row, or use LIMIT 1.
诊断
先看是否是严格目标赋值或 modifying statement,再检查完整 detail/hint。固定源码先按 plpgsql.extra_errors/plpgsql.extra_warnings 对 too_many_rows 的选择设置级别:前者优先并使用 ERROR,只有后者生效时才使用 WARNING;strict/modifying 路径无论这些设置如何都使用 ERROR,所以不要只凭条件名断言严重级别。
处置
让查询满足单行契约,或改用能表达多行结果的 PL/pgSQL 结构;若业务允许第一行,必须显式设计排序和截取语义,而不是盲目套用 hint。修正查询契约后再执行,避免把同一多行结果自动重放成重复业务操作。
版本
锁定目录从 8.2.0 记录该条件,并在列出的正式快照及 19beta3 中出现;运行时未在本批次重演。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 493 行
- 上游源码 src/pl/plpgsql/src/pl_exec.c 第 4215–4220 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
P0003 is too_many_rows in PostgreSQL-specific Class P0.
-
PL/pgSQL fixed paths report `query returned more than one row`; the strict path may include `parameters: %s` and the source provides the hint `Make sure the query returns a single row, or use LIMIT 1.`.
-
For SELECT INTO-style checked queries, plpgsql.extra_errors selecting too_many_rows takes precedence and sets the extra check to ERROR; if it is not selected, plpgsql.extra_warnings selecting too_many_rows sets WARNING. Strict or modifying-statement paths use ERROR regardless, and print_strict_params controls the optional parameters detail.
同类错误代码
Class P0 PL/pgSQL错误 下的其他成员。