December 20th, 2012, 08:45 AM
Rollback from function calling another function
I have a function "function1" then I have another 2 functions "function2" & "function3". "function2" and "function3" insert records in different tables and a boolean value is returns true if the insert is successfull. "function1" calls the other 2 functions in sequence.
DECLARE return_value BOOLEAN;
SELECT * FROM function2() INTO return_value;
SELECT * FROM function3() INTO return_value;
I need to rollback both functions if function3 is unsuccessfull. Can this be achieved cause function2 seems to commit the changes as soon as it finishes.
December 20th, 2012, 09:21 AM
A function in PostgreSQL can't commit, so function2 cannot commit "on its own".
You are probably running in auto-commit mode.
You need to call all functions inside a transaction then you can commit or rollback everything after the functions are finished.
I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
Tips on how to ask better questions:
December 20th, 2012, 09:35 AM
Could you please give me an example.