I have one question about the function flow in PostgreSQL. I used function to insert/update in table A and the function return integer value 1-> insert transaction, 0->update transaction. My question is if I add AFTER trigger in table A to update the new value to table B, when the return function will be delivered? First or second scenario?

First scenario: Call function -> update table A -> return function value -> call trigger -> update table B

Second scenario: Call function -> update table A -> call trigger -> update table B -> return function value?

Thanks in advance.

share
    
Question isn't very clear... – Denis de Bernardy Dec 9 '13 at 10:20
    
I want to know if I call function to update table A, and where table A have trigger to update table B. When the function will return the integer value? First or second scenario? Thanks – user430926 Dec 9 '13 at 10:48
    
I desagre with @Denis the question has all elements to understand the problem. – Jorge Campos Dec 9 '13 at 10:53
1  
@JorgeCampos: it does now. It didn't a half hour ago. :-) – Denis de Bernardy Dec 9 '13 at 10:55
up vote 1 down vote accepted
+50

The second scenario. Updating B will be part of updating A, and your function will wait until that completes before returning.

share
    
Do you have any article/document that suggest it's the second scenario? Thanks. – user430926 Dec 9 '13 at 10:59
    
Not off the top of my head, but per specs, a statement and all of the triggers it fires are part of the same transaction. You can readily see this by consulting the xmin of affected rows (they'll all be the same) or raising an arbitrary error in an after trigger (in which case your entire transaction is rolled back and your function will return nothing). – Denis de Bernardy Dec 9 '13 at 20:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.