Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 03297B5DBD8 for ; Tue, 19 Jul 2011 15:31:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 54190-04 for ; Tue, 19 Jul 2011 18:31:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 5F38BB5D944 for ; Tue, 19 Jul 2011 15:31:40 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p6JIVdjh055847 for ; Tue, 19 Jul 2011 18:31:39 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p6JIVdxu055846; Tue, 19 Jul 2011 18:31:39 GMT (envelope-from www) Date: Tue, 19 Jul 2011 18:31:39 GMT Message-Id: <201107191831.p6JIVdxu055846@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6123: DELETE fails if before trigger causes another trigger to UPDATE From: "Kevin Grittner" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201107/139 X-Sequence-Number: 30751 The following bug has been logged online: Bug reference: 6123 Logged by: Kevin Grittner Email address: Kevin.Grittner@wicourts.gov PostgreSQL version: HEAD and 9.0.4 Operating system: Linux (probably doesn't matter) Description: DELETE fails if before trigger causes another trigger to UPDATE Details: create table a (aid int not null primary key, bcnt int not null default 0); create table b (bid int not null primary key, aid int not null); create function a_del_func() returns trigger language plpgsql as $$begin delete from b where aid = old.aid; return old; end;$$; create trigger a_del_trig before delete On a for each row execute procedure a_del_func(); create function b_ins_func() returns trigger language plpgsql as $$begin update a set bcnt = bcnt + 1 where aid = new.aid; return new; end;$$; create trigger b_ins_trig after insert on b for each row execute procedure b_ins_func(); create function b_del_func() returns trigger language plpgsql as $$begin update a set bcnt = bcnt - 1 where aid = old.aid; return old; end;$$; create trigger b_del_trig after delete on b for each row execute procedure b_del_func(); insert into a values (1, 0); insert into b values (10, 1); select * from a; select * from b; delete from a where aid = 1; select * from a; select * from b; I expect the DELETE from a to delete related b record(s) and then succeed. Instead the UPDATE in b_del_trig causes delete of a to silently fail. -Kevin