I am using simple function for exception handling the code is..
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;
but it is giving ERROR: syntax error at or near "STACKED" GET STACKED DIAGNOSTICS
.
I am using postGreSql 9.1 and pgadmin 3.
You need to upgrade to postgreSQL 9.2 ... 9.1 version doesn't support GET STACKED DIAGNOSTICS as far as I know .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With