-
Notifications
You must be signed in to change notification settings - Fork 38
Description
So, SQL has two features that essentially do the same thing. First you have to use begin … rollback / commit
, and then inside it you can use savepoint … rollback to savepoint / release savepoint
, and you can do that any number of times, effectively creating arbitrary nesting of transactions.
This means that in principle transactions compose. But at present, if I wrap a snaplet that uses a transaction into another snaplet that also uses a transaction, it will be a mess: the transaction will start at the first begin
, the inner begin
will be ignored, then the inner rollback / commit
will affect everything back to the first begin
and the final rollback / commit
will be ignored. Good for me that PostgreSQL emits a warning in such cases!
This is not in principle a problem — we only need to track in the HasPostgres
monad what the current nesting level is. Then we can intelligently choose whether to use begin
or savepoint
. For bonus points, we may also carry around a source of fresh names for save points — this would be required for vanilla SQL, but PostgreSQL allows using the same name for nested save points, so it is not necessary.
Can we have this feature? I am considering writing it for a private project and if it goes well I may be able to contribute a patch.