我正在使用简单的函数来处理异常,代码是..
CREATE OR REPLACE FUNCTION test(INT4) RETURNS void as $$
DECLARE
v_state TEXT;
v_msg TEXT;
v_detail TEXT;
v_hint TEXT;
v_context TEXT;
BEGIN
BEGIN
INSERT INTO test2 (id) VALUES ($1);
EXCEPTION WHEN others THEN
GET STACKED DIAGNOSTICS
v_state = RETURNED_SQLSTATE,
v_msg = MESSAGE_TEXT,
v_detail = PG_EXCEPTION_DETAIL,
v_hint = PG_EXCEPTION_HINT,
v_context = PG_EXCEPTION_CONTEXT;
raise notice E'Got exception:
state : %
message: %
detail : %
hint : %
context: %', v_state, v_msg, v_detail, v_hint, v_context;
END;
RETURN;
END;
$$ language PLpgSQL;
但它正在给予 ERROR: syntax error at or near "STACKED" GET STACKED DIAGNOSTICS
。
我正在使用 postGreSql 9.1 和 pgadmin 3。