DBMS_UTILITY.FORMAT_CALL_STACK
Postgres for Oracle和的同等/最接近的替代方案是DBMS_UTILITY.FORMAT_ERROR_STACK
什么?
问问题
572 次
1 回答
2
您可以使用GET DIAGNOSTICS
或GET 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 回答