Can Multiple Transactions Work In Cascade Triggers And Functions? - Mailing list pgsql-general

From cn
Subject Can Multiple Transactions Work In Cascade Triggers And Functions?
Date
Msg-id 39B06068.4AA4912A@mail.sinyih.com.tw
Whole thread Raw
List pgsql-general
Hello!

For example, if the database has 3 tables: table1, table2, table3, and 2
triggers, and 2 functions as follows:

(s1)CREATE FUNCTION function1() RETURNS OPAQUE AS'
(s2)BEGIN WORK;
(s3)-- update table2
(s4)IF fail THEN
(s5)  ROLLBACK WORK;
(s6)ELSE
(s7)  COMMIT WORK;
(s8)END IF;'

CREATE trigger1 BEFORE update ON table1
FOR EACH ROW EXECUTE PROCEDURE function1();

--version 1 for function2()
(s9)CREATE FUNCTION function2() RETURNS OPAQUE AS'
(s10)BEGIN WORK;
(s11)-- update table3
(s12)IF fail THEN
(s13)  ROLLBACK WORK;
(s14)ELSE
(s15)  COMMIT WORK;
(s16)END IF;'

--version 2 for function2()
(s17)CREATE FUNCTION function2() RETURNS OPAQUE AS'
(s18)-- update table3'

CREATE trigger2 BEFORE update ON table2
FOR EACH ROW EXECUTE PROCEDURE function2();

Does these triggers and functions make sense?
Which version of function2() is OK?
What will the database be when statement (s11) or (s18) fails?
What are the exact procedures/techniques that I should apply in order to
guarantee ALL-OR-NO-TRANSACTIONS-BE-DONE in triggers and functions?

Thanks and Regards,

CN

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: install 7.0.2 host
Next
From: Alex Guryanow
Date:
Subject: PL/Perl compilation error