Re: trigger before delete question - Mailing list pgsql-sql

From Tom Lane
Subject Re: trigger before delete question
Date
Msg-id 1386.1240323224@sss.pgh.pa.us
Whole thread Raw
In response to trigger before delete question  (Sigrid Thijs <sigrid.thijs@gmail.com>)
List pgsql-sql
Sigrid Thijs <sigrid.thijs@gmail.com> 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


pgsql-sql by date:

Previous
From: Sigrid Thijs
Date:
Subject: trigger before delete question
Next
From: ShuA
Date:
Subject: Re[3]: Need a script that bakes INSERT script from SELECT results