Question: how do transactions and locking work w/ triggers? Let's say I have a table with an update trigger defined on it. I execute a query that updates row N in that table. Which, if any, of the following occur, and if none than what does occur?
Scenario A
1. begin transaction
2. the job obtains an exclusive lock on row N and the update is made
3. the trigger executes
4. the lock on row N is released (end transaction)
Scenario B
1. the trigger executes (begin + end transaction)
2. begin new transaction
3. the job obtains an exclusive lock on row N and the update is made
4. the lock on row N is released (end transaction)
Scenario C
1. begin transaction
2. the job obtains an exclusive lock on row N and the update is made
3. the lock on row N is released (end transaction)
4. the trigger executes (begin and end new transaction)
On the one hand, it might seem that scenario B or C is the correct one, because the documentation for triggers states that if a "rollback transaction" statement occurs within a trigger, it will roll back the transaction that contains the insert/update/delete statement that caused the trigger to occur. However, I just tried putting an infinite while loop in a trigger and using a different connection to query the table that the trigger is attached to, and the second connection blocked, probably waiting for the while loop to finish.
Any help on this is appreciated -- thanks in advance.
Scenario A
1. begin transaction
2. the job obtains an exclusive lock on row N and the update is made
3. the trigger executes
4. the lock on row N is released (end transaction)
Scenario B
1. the trigger executes (begin + end transaction)
2. begin new transaction
3. the job obtains an exclusive lock on row N and the update is made
4. the lock on row N is released (end transaction)
Scenario C
1. begin transaction
2. the job obtains an exclusive lock on row N and the update is made
3. the lock on row N is released (end transaction)
4. the trigger executes (begin and end new transaction)
On the one hand, it might seem that scenario B or C is the correct one, because the documentation for triggers states that if a "rollback transaction" statement occurs within a trigger, it will roll back the transaction that contains the insert/update/delete statement that caused the trigger to occur. However, I just tried putting an infinite while loop in a trigger and using a different connection to query the table that the trigger is attached to, and the second connection blocked, probably waiting for the while loop to finish.
Any help on this is appreciated -- thanks in advance.