Hello all! Trying to emulate "named" user defined exception with: CREATE OR REPLACE FUNCTION exception_aaa () RETURNS text AS $body$ BEGIN return 31234; END; $body$ LANGUAGE PLPGSQL SECURITY DEFINER ;
do $$ begin raise exception using errcode=exception_aaa(); exception when sqlstate exception_aaa() then raise notice 'got exception %',sqlstate; end; $$
Got:
ERROR: syntax error at or near "exception_aaa" LINE 20: sqlstate exception_aaa()
I looks like "when sqlstate exception_aaa()" doesn't work.
How can I catch exception in this case?
this syntax is working only for builtin exceptions. PostgreSQL has not declared custom exceptions like SQL/PSM.
You have to use own sqlcode and catch specific code.