Is it possible to cancel previous operations in a user defined function?
For example:
CREATE OR REPLACE FUNCTION transact_test () RETURNS BOOLEAN
AS $$
BEGIN
UPDATE table1 SET ...
UPDATE table2 SET ...
IF some_condition THEN
--Here is possible to cancel all above operations?
RETURN FALSE;
END IF;
RETURN TRUE;
END;
$$
LANGUAGE plpgsql;
Both answers so far are incorrect.
If you try to start a transaction or use a
SAVEPOINT
inside a plpgsql function you get an error message like this:If you try a
SAVEPOINT
inside a plain SQL function:As the error message instructs, use a
BEGIN
block inside a plpgsql function instead. Your demo could look like this:-> SQLfiddle demonstrating it all.