Oracle DBMS_UTILITY.FORMAT_CALL_STACK 和 DBMS_UTILITY.FORMAT_ERROR_STACK 的 Postgres 替代品
Postgres alternatives for Oracle DBMS_UTILITY.FORMAT_CALL_STACK and DBMS_UTILITY.FORMAT_ERROR_STACK
Postgres for Oracle DBMS_UTILITY.FORMAT_CALL_STACK
和 DBMS_UTILITY.FORMAT_ERROR_STACK
中的 equal/closest 替代品是什么?
您可以使用 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)
Postgres for Oracle DBMS_UTILITY.FORMAT_CALL_STACK
和 DBMS_UTILITY.FORMAT_ERROR_STACK
中的 equal/closest 替代品是什么?
您可以使用 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)