Hello!
A critical question for me because of future planning.
In autocommit mode, when I start a simple update or select, it is one transaction, so if something fails, the whole modification is rolled back (there is no "half update", or "only first record updated").
What will happen with complex statements, like PLPGSQL stored procedure, or trigger?
Pseudo:
BEGIN
select a from b ... into X;
update b set a = X + 1 where ...;
update b set mod_date = current_timestamp where ...;
IF bla THEN raise Exception 'Wrong';
select x from y;
call stored procedure N;
...
update b set mod_date = current_timestamp where ...;
END;
Is it also one statement logically (doesn't matter it would be recursive)?
Is this executed in one transaction? Or each substatement is a new transaction?
So if the half executed but we got an exception in the center:
a.) the whole rolled back,
b.) or it is halfly finished and only the last substatement rolled back.
The main question is:
Do I need to embed the whole call into a directly started transaction block to keep consistency - or this isn't needed because this is handled by PG as one big statement with many sub statements?
This is also important for triggers to...
Triggers (insert/update/delete) also could start subprocedures with substatements, so if I don't wrap around a directly started transaction, maybe I will get the wrong result (not ALL OK/ALL FAILS).
Thank you for your help!
Best regards
dd