AFTER INSERTING a trigger in a separate transaction?

Will the AFTER INSERT trigger (function written in pl / PGsql) work in a separate transaction than the original insert?

What bothers me is if the trigger has some kind of exception.
Is it possible to roll back a trigger without initial insertion?

+6
source share
2 answers

All PostgreSQL triggers are executed in the same transaction as the transaction that caused them.

Change You can also use LISTEN + NOTIFY to send a message from your trigger to code that runs outside of the transaction. In this case, the message will be delivered only at the time of a successful commit. Errors in listeners will not roll back the transaction operation.

+13
source

Trigger procedures are executed in the same transaction as the associated trigger events. But the effects of the trigger procedure can be discarded separately.

You must add exception handling to the trigger after starting.

+6
source

Source: https://habr.com/ru/post/916494/


All Articles