Re: Trigger firing order odd?

From: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Trigger firing order odd?
Date: 2003-05-02 05:18:38
Message-ID: 5.1.0.14.0.20030502151626.0622b4f0@mail.rhyme.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Sample code should have been:

CREATE TABLE zzz (
f1 integer
);

--
-- TOC entry 632 (OID 3098251)
-- Name: zzz_tg_proc (); Type: FUNCTION; Schema: public; Owner: pgsql
--

CREATE or REPLACE FUNCTION zzz_tg_proc () RETURNS "trigger"
AS 'Begin Raise NOTICE ''In trigger %'',TG_NAME; return NEW;end'
LANGUAGE plpgsql;

CREATE FUNCTION zzz_proc () RETURNS void
AS 'Begin Raise NOTICE ''In proc'';
update zzz set f1 = 2 where f1=1;
Raise NOTICE ''Updating again'';
update zzz set f1 = 1 where f1=2;
Raise NOTICE ''Leaving Proc'';
return;
end;' Language 'plpgsql';

CREATE TRIGGER zzz_upd_bef_tg
BEFORE UPDATE ON zzz
FOR EACH ROW
EXECUTE PROCEDURE zzz_tg_proc ();

CREATE TRIGGER zzz_upd_aft_tg
AFTER UPDATE ON zzz
FOR EACH ROW
EXECUTE PROCEDURE zzz_tg_proc ();

CREATE TRIGGER zzz_add_bef_tg
BEFORE INSERT ON zzz
FOR EACH ROW
EXECUTE PROCEDURE zzz_tg_proc ();

CREATE TRIGGER zzz_add_aft_tg
AFTER INSERT ON zzz
FOR EACH ROW
EXECUTE PROCEDURE zzz_tg_proc ();

insert into zzz values(1);
NOTICE: In trigger zzz_add_bef_tg
NOTICE: In trigger zzz_add_aft_tg

select zzz_proc();
NOTICE: In proc
NOTICE: In trigger zzz_upd_bef_tg
NOTICE: Updating again
NOTICE: In trigger zzz_upd_bef_tg
NOTICE: Leaving Proc
NOTICE: In trigger zzz_upd_aft_tg
NOTICE: In trigger zzz_upd_aft_tg

----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 03 5330 3172 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp5.ai.mit.edu:11371 |/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Manfred Koizar 2003-05-02 09:27:47 comp.databases.postgresql.patches not working
Previous Message Philip Warner 2003-05-02 05:09:06 Trigger firing order odd?