0

DBMS_UTILITY.FORMAT_CALL_STACKPostgres for Oracle和的同等/最接近的替代方案是DBMS_UTILITY.FORMAT_ERROR_STACK什么?

4

1 回答 1

2

您可以使用GET DIAGNOSTICSGET STACKED DIAGNOSTICS声明并读取PG_CONTEXT字段。

CREATE OR REPLACE FUNCTION outer_func() RETURNS integer AS $$
BEGIN
  RETURN inner_func();
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION inner_func() RETURNS integer AS $$
DECLARE
  stack text;
BEGIN
  GET DIAGNOSTICS stack = PG_CONTEXT;
  RAISE NOTICE E'--- Call Stack ---\n%', stack;
  RETURN 1;
END;
$$ LANGUAGE plpgsql;

SELECT outer_func();

NOTICE:  --- Call Stack ---
PL/pgSQL function inner_func() line 5 at GET DIAGNOSTICS
PL/pgSQL function outer_func() line 3 at RETURN
CONTEXT:  PL/pgSQL function outer_func() line 3 at RETURN
outer_func
------------
        1
(1 row)
于 2020-07-09T15:46:05.680 回答