Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 378FF63347C for ; Tue, 21 Apr 2009 11:13:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 74757-07 for ; Tue, 21 Apr 2009 11:13:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id A8388632CA7 for ; Tue, 21 Apr 2009 11:13:47 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n3LEDilS001387; Tue, 21 Apr 2009 10:13:44 -0400 (EDT) To: Sigrid Thijs cc: pgsql-sql@postgresql.org Subject: Re: trigger before delete question In-reply-to: <23f7d19d0904210503h4eaaef70q96c4338d71f73fee@mail.gmail.com> References: <23f7d19d0904210503h4eaaef70q96c4338d71f73fee@mail.gmail.com> Comments: In-reply-to Sigrid Thijs message dated "Tue, 21 Apr 2009 14:03:50 +0200" Date: Tue, 21 Apr 2009 10:13:44 -0400 Message-ID: <1386.1240323224@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.159 tagged_above=0 required=5 tests=AWL=0.159 X-Spam-Level: X-Archive-Number: 200904/108 X-Sequence-Number: 32454 Sigrid Thijs writes: > I've bumped into a problem with a trigger before delete that I do not > immediately understand. I have made a simple example that also illustrates > the issue, but in reality the database structure is more complex. The reason it doesn't work is that the delete from member cascades back to update the club row (ie, set contact_member_id to null) and so by the time the original delete is attempted the row version it's against is already obsolete. That results in nothing happening, not in re-issuing the delete against the updated row version. Personally I'd recommend rethinking this unholy mix of recursive foreign keys and bad manual substitutes for foreign keys. However, if you can't come up with a less bogus schema design, you might find that it helps to propagate information to derived rows in AFTER triggers rather than BEFORE triggers. regards, tom lane