I was wondering if it is possible to indirectly trigger a trigger executed just before a transaction? In this trigger, I will perform consistency checks and roll back the transaction, if necessary.
For example, I have three tables:
users (id, name) groups (id, name) user_in_group (user_id, group_id)
I would like to create a trigger that checks that the user is always part of a group. The use of orphans is not permitted. Each time an insert into users occurs, this trigger will check that an offset insert is also inserted into user_in_group. If not, the transaction will not be completed.
This cannot be done with a simple trigger based on a string or an operator, since two separate statements are required in the above scenario.
Another way, when a deletion from user_in_group occurs, can be easily done using a row-based trigger.
triggers postgresql transactions
Appelsien S.
source share