I'm new to Postgresql, so I don't want to create my own structures for some basic tasks....
My task is to create function and throw exception (RAISE EXCEPTION 'test') in some conditions for client to catch it or rethrow in case of not handling it properly. The problem is that before throwing I wanted to LOG the exception to special table in the database, but realized that throwing error is rollbacking the changes made before! Is there any way to change this behavior or all I can do - add some CODE output parameter and throw errors on the client based on that CODE? Sample code that I'm using now:
CREATE OR REPLACE FUNCTION fn_...()
...
BEGIN
IF nretry_count >= nmax_retry
THEN
INSERT INTO log VALUES (error_type, value) VALUES (1,'Max retry exceeded!');
RAISE EXCEPTION 'Max retry count exceeded';
END IF;
END
$$ LANGUAGE plpgsql;
before insert. In a Trigger-Function you could raise the exception and log the data to another table. postgresql.org/docs/9.6/static/plpgsql-trigger.html