0Z002
Read PG 18 manual ↗stacked_diagnostics_accessed_without_active_handler
- SQLSTATE
- 0Z002
- Condition name
- stacked_diagnostics_accessed_without_active_handler
- Class
- Diagnostics Exception
- Source macro
- ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
SQLSTATE 0Z002 is emitted by PL/pgSQL when code tries to use stacked exception state without the active exception handler that owns it. PostgreSQL 18.6 has two confirmed paths: GET STACKED DIAGNOSTICS cannot be used outside an exception handler and RAISE without parameters cannot be used outside an exception handler, both reported at ERROR level.
Meaning
The first path guards GET STACKED DIAGNOSTICS; the second guards a parameterless RAISE that would re-raise the current exception. The shared boundary is the PL/pgSQL EXCEPTION handler, not a SQL BEGIN/COMMIT transaction block. The SQLSTATE member is more specific than the 0Z000 category.
Messages
The fixed messages are GET STACKED DIAGNOSTICS cannot be used outside an exception handler and RAISE without parameters cannot be used outside an exception handler.
Diagnosis
Locate the failing PL/pgSQL statement and the nearest EXCEPTION block. GET STACKED DIAGNOSTICS reads the exception being handled, while parameterless RAISE re-raises it; neither has stacked state outside a handler. Preserve the exact message and routine context because a transaction-state error or a new explicit RAISE has a different cause.
Response
Move the diagnostic read or re-raise into the active exception handler, or use an explicit RAISE condition/message when no prior exception is being handled. Keep the handler narrow and preserve RETURNED_SQLSTATE, message, detail, and hint before leaving it. A code change, rather than a transaction retry, is the repair supported by this path.
Versions
The locked catalogue places this condition at least by PostgreSQL 9.2.0. The release definitions cover the published snapshots listed in the facts block; source-path status is limited to the fixed PostgreSQL 18.6 context cited below.
Sources
The fixed PL/pgSQL executor source reports the GET STACKED DIAGNOSTICS variant, and the RAISE path reports the parameterless variant. The PL/pgSQL diagnostics documentation describes stacked fields. See the structured evidence record for fixed source paths, scan scope, and unresolved runtime boundaries.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
0Z002 is stacked_diagnostics_accessed_without_active_handler in SQLSTATE Class 0Z.
Method: Read the fixed errcodes definition row, severity, and macro.
The fixed PostgreSQL 18.6 source contains the report path and message context described on the page.
Method: Read the complete source context around the resolved report group.
Limits: This is source confirmation, not a runtime observation in this batch.
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.
Method: Compare canonical release-definition facts with the available history boundary.
Limits: Definition presence is not an emitting-path observation.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/pl/plpgsql/src/pl_exec.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·
Message templates
ERROR · message.get-stacked-outside-handler
Primary
GET STACKED DIAGNOSTICS cannot be used outside an exception handler
ERROR · message.raise-without-parameters-outside-handler
Primary
RAISE without parameters cannot be used outside an exception handler
Reproduction & repair cases
No reproduction case is attached to this condition.
Recorded runtime evidence
No runtime observation is attached to this entry.
Version history 1
- PG 9.1 → 9.2added
Definition snapshot: english-manuals:0adea3fb623cce2d3e4fdccb71f… · English manual source