Dominique Devienne <ddevienne@gmail.com> writes:
> Hi Erik. And experts at large. What's the underlying mechanism though? An
> implicit SAVEPOINT?
Yes, savepoints and plpgsql exception blocks are built on the same
"subtransaction" infrastructure.
> Which means extra explicit round-trips to the server to establish and "move
> along" the savepoint,
> per command. Which I think is "expensive". So would anonymous DO blocks be
> a better solution?
In general, moving logic to the server side is an effective way of
removing network round trips. That could be DO blocks, functions,
or procedures. If you're going to execute the same code over and
over within a session, a function or procedure will probably be
a better choice than re-issuing identical DO blocks.
regards, tom lane