1

I have the function insert_val that inserts some values into some tables. These tables have triggers that raises exception when something is wrong. How can I rollback the function whenever a trigger raises exception and go to the next curs1 is this possible? Thanks in advance

res :='start';
OPEN curs1 FOR SELECT temp3.fid FROM temp3; 
LOOP 

FETCH curs1 INTO fidVar;
EXIT WHEN NOT FOUND;
BEGIN
if raise_exception then
rollback;
end if;
perform insert_val(fidVar,startDate,endDate);    
END;
END LOOP;

1 Answer 1

1

You cannot ROLLBACK from a trigger or function, because transaction control is not possible within functions.

What you actually seem to want is to skip and continue after an exception. You can do this using BEGIN ... EXCEPTION blocks in PL/PgSQL, per the manual. Internally this uses subtransactions just like SAVEPOINT and ROLLBACK TO SAVEPOINT.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.