pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: pgsql-bugs@postgresql.org
Subject: BUG #6123: DELETE fails if before trigger causes another trigger to UPDATE
Date: Tue, 19 Jul 2011 18:31:39 GMT
Message-ID: <201107191831.p6JIVdxu055846@wwwmaster.postgresql.org> (raw)


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



view thread (5+ messages)  latest in thread

Message-ID: <201107191831.p6JIVdxu055846@wwwmaster.postgresql.org>
Permalink:  ../201107191831.p6JIVdxu055846@wwwmaster.postgresql.org/
Also on:    postgresql.org/message-id/201107191831.p6JIVdxu055846@wwwmaster.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: Kevin.Grittner@wicourts.gov
  Subject: Re: BUG #6123: DELETE fails if before trigger causes another trigger to UPDATE
  In-Reply-To: <201107191831.p6JIVdxu055846@wwwmaster.postgresql.org>
  References: <201107191831.p6JIVdxu055846@wwwmaster.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox