0

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.

4
  • Question isn't very clear... Commented Dec 9, 2013 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 Commented Dec 9, 2013 at 10:48
  • I desagre with @Denis the question has all elements to understand the problem. Commented Dec 9, 2013 at 10:53
  • 1
    @JorgeCampos: it does now. It didn't a half hour ago. :-) Commented Dec 9, 2013 at 10:55

1 Answer 1

1
+50

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

Sign up to request clarification or add additional context in comments.

2 Comments

Do you have any article/document that suggest it's the second scenario? Thanks.
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.