选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 0Z 诊断异常

0Z002 stacked_diagnostics_accessed_without_active_handler

ERROR 源码确认 参考 未实测

类别
Class 0Z 诊断异常
严重等级
ERROR
条件名
stacked_diagnostics_accessed_without_active_handler
宏名称
ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER
启用版本
9.2
状态
活跃

版本覆盖

速览

SQLSTATE 0Z002 在 PL/pgSQL 代码试图使用堆叠异常状态、但不存在拥有该状态的活动异常处理器时报告。PostgreSQL 18.6 已确认两条路径:GET STACKED DIAGNOSTICS cannot be used outside an exception handlerRAISE without parameters cannot be used outside an exception handler,两者均为 ERROR。

含义

第一条路径保护 GET STACKED DIAGNOSTICS;第二条路径保护本应重新抛出当前异常的无参数 RAISE。共同边界是 PL/pgSQL 的 EXCEPTION 处理器,而不是 SQL 的 BEGIN/COMMIT 事务块。该成员码比 0Z000 类别更具体。

消息

固定消息是 GET STACKED DIAGNOSTICS cannot be used outside an exception handlerRAISE without parameters cannot be used outside an exception handler

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 GET STACKED DIAGNOSTICS cannot be used outside an exception handler

来源:src/pl/plpgsql/src/pl_exec.c @ REL_18_6

主消息 RAISE without parameters cannot be used outside an exception handler

来源:src/pl/plpgsql/src/pl_exec.c @ REL_18_6

诊断

定位失败的 PL/pgSQL 语句及最近的 EXCEPTION 块。GET STACKED DIAGNOSTICS 读取正在处理的异常,无参数 RAISE 重新抛出该异常;处理器外不存在可用的堆叠状态。保留准确消息和 routine context,因为事务状态错误或新的显式 RAISE 属于不同原因。

处理

把诊断读取或重新抛出移到活动异常处理器中;如果当前没有正在处理的异常,就使用带明确条件/消息的 RAISE。处理器应保持足够窄,并在离开前保留 RETURNED_SQLSTATE、消息、detail 和 hint。该路径支持的是代码修正,而不是事务重试。

版本

锁定目录将该条件的已知下界记为 PostgreSQL 9.2.0。事实块列出已发布快照;源码路径状态仅限于下方固定的 PostgreSQL 18.6 资料。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 0Z002 is stacked_diagnostics_accessed_without_active_handler in SQLSTATE Class 0Z.

    核实方式Read the fixed errcodes definition row, severity, and macro.

    来源src/backend/utils/errcodes.txt

  • The fixed PostgreSQL 18.6 source contains the report path and message context described on the page.

    核实方式Read the complete source context around the resolved report group.

    不覆盖This is source confirmation, not a runtime observation in this batch.

    来源src/pl/plpgsql/src/pl_exec.c

  • The locked release definitions establish catalogue presence from the known 9.2.0 boundary; they do not establish a precise introducing release or runtime use.

    核实方式Compare canonical release-definition facts with the available history boundary.

    不覆盖Definition presence is not an emitting-path observation.

    来源src/backend/utils/errcodes.txt

同类错误代码

Class 0Z 诊断异常 下的其他成员。