↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

0Z002 — stacked_diagnostics_accessed_without_active_handler

在异常处理器外访问堆叠诊断状态。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Diagnostics Exception
condition name
stacked_diagnostics_accessed_without_active_handler
lang
en
sqlstate
0Z002

版本定义 PG 18

0Z002

速览 {#at-a-glance}

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

含义 {#meaning}

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

消息 {#messages}

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

诊断 {#diagnosis}

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

处理 {#response}

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

版本 {#versions}

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

相关 {#related}

0Z000, P0001

来源 {#sources}

固定的 PL/pgSQL 执行器源码报告 GET STACKED DIAGNOSTICS 变体,RAISE 路径报告无参数变体。PL/pgSQL 诊断文档说明堆叠字段。 详见结构化证据记录,其中记录固定源码路径、扫描范围和未解决的运行边界。

比较版本

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": "0Z002 is stacked_diagnostics_accessed_without_active_handler in SQLSTATE Class 0Z."
}
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.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 9.2.0 boundary; they do not establish a precise introducing release or runtime use."
}
messages · message.get-stacked-outside-handler
{
  "limits": "",
  "message_id": "message.get-stacked-outside-handler",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.get-stacked-outside-handler",
    "primary_template": "GET STACKED DIAGNOSTICS cannot be used outside an exception handler",
    "severity_source": "ERROR",
    "sources": [
      "src.pl_exec.18.6"
    ],
    "sqlstate": "0Z002"
  },
  "severity": "ERROR",
  "sources": [
    "src.pl_exec.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "GET STACKED DIAGNOSTICS cannot be used outside an exception handler",
      "position": 0,
      "role": "",
      "template": "GET STACKED DIAGNOSTICS cannot be used outside an exception handler"
    }
  ]
}
messages · message.raise-without-parameters-outside-handler
{
  "limits": "",
  "message_id": "message.raise-without-parameters-outside-handler",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.raise-without-parameters-outside-handler",
    "primary_template": "RAISE without parameters cannot be used outside an exception handler",
    "severity_source": "ERROR",
    "sources": [
      "src.pl_exec.18.6"
    ],
    "sqlstate": "0Z002"
  },
  "severity": "ERROR",
  "sources": [
    "src.pl_exec.18.6"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "RAISE without parameters cannot be used outside an exception handler",
      "position": 0,
      "role": "",
      "template": "RAISE without parameters cannot be used outside an exception handler"
    }
  ]
}
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#L142"
}
sources · src.pl_exec.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.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": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:4279fcb65c55c3c763ccff3bc8f63fd08daa08dfad9ff6ab28936823e54a9d33

正文语言: zh-Hans · english-manuals:4279fcb65c55c3c763ccff3bc8f63fd08daa08dfad9ff6ab28936823e54a9d33