Seaquel
PostgreSQL error code

PostgreSQL error 0Z002

0Z002 is the SQLSTATE PostgreSQL reports for stacked diagnostics accessed without active handler, in class 0Z, Diagnostics Exception.

SQLSTATE0Z002
Condition namestacked_diagnostics_accessed_without_active_handler
Class0Z — Diagnostics Exception

Reproduce it, then fix it

GET STACKED DIAGNOSTICS reads the error being handled, so it only works inside an EXCEPTION block. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

DO $$
DECLARE
  msg text;
BEGIN
  GET STACKED DIAGNOSTICS msg = MESSAGE_TEXT;
END $$;
DO $$
DECLARE
  msg text;
BEGIN
  PERFORM 1 / 0;
EXCEPTION WHEN others THEN
  GET STACKED DIAGNOSTICS msg = MESSAGE_TEXT;
  RAISE NOTICE 'caught: %', msg;
END $$;

Source: PostgreSQL documentation, Appendix A