Can Multiple Transactions Work In Cascade Triggers And Functions?

From: cn <cn(at)mail(dot)sinyih(dot)com(dot)tw>
To: pgsql-general(at)postgresql(dot)org
Subject: Can Multiple Transactions Work In Cascade Triggers And Functions?
Date: 2000-09-02 02:05:28
Message-ID: 39B06068.4AA4912A@mail.sinyih.com.tw
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message Alex Guryanow 2000-09-02 08:47:58 PL/Perl compilation error
Previous Message Tom Lane 2000-09-01 21:57:14 Re: install 7.0.2 host