From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sigrid Thijs <sigrid.thijs@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: trigger before delete question
Date: Tue, 21 Apr 2009 10:13:44 -0400
Message-ID: <1386.1240323224@sss.pgh.pa.us> (raw)
In-Reply-To: <23f7d19d0904210503h4eaaef70q96c4338d71f73fee@mail.gmail.com>
References: <23f7d19d0904210503h4eaaef70q96c4338d71f73fee@mail.gmail.com>
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
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, sigrid.thijs@gmail.com
Subject: Re: trigger before delete question
In-Reply-To: <1386.1240323224@sss.pgh.pa.us>
* 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