Re: trigger before delete question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sigrid Thijs <sigrid(dot)thijs(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: trigger before delete question
Date: 2009-04-21 14:13:44
Message-ID: 1386.1240323224@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Sigrid Thijs <sigrid(dot)thijs(at)gmail(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message ShuA 2009-04-23 08:34:49 Re[3]: Need a script that bakes INSERT script from SELECT results
Previous Message Sigrid Thijs 2009-04-21 12:03:50 trigger before delete question