Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do queries executed in a Postgres trigger procedure run in the same transaction?

I have a BEFORE DELETE trigger which inserts rows into another table using SPI_exec.

Do these INSERT queries run in the same transaction as the one in which the original delete is executing? Hence, will the delete and all inserts roll back or commit together?

If not, how can I make that happen?

like image 442
Roman Starkov Avatar asked Dec 12 '25 12:12

Roman Starkov


1 Answers

Yes, everything in triggers is in the same transaction as the triggering event.

Not directly related to the question, but normally you want to put side-effects in the AFTER trigger, rather than the BEFORE trigger.

like image 91
kgrittn Avatar answered Dec 14 '25 10:12

kgrittn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!