Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL Exception handling detail with GET STACKED DIAGNOSTICS

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.

like image 658
khushbu Avatar asked Oct 05 '22 05:10

khushbu


1 Answers

You need to upgrade to postgreSQL 9.2 ... 9.1 version doesn't support GET STACKED DIAGNOSTICS as far as I know .

like image 67
aleroot Avatar answered Oct 13 '22 11:10

aleroot