Re: Shouldn't ON UPDATE/DELETE triggers be BEFORE triggers?

From: "Stephan Szabo" <acroyear_07030(at)yahoo(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Shouldn't ON UPDATE/DELETE triggers be BEFORE triggers?
Date: 2001-04-02 21:11:15
Message-ID: 003e01c0bbb9$765f8810$02de010a@myst.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> While thinking over Jeremy Radlow's recent problem report in
> pgsql-general, it occurs to me that it's probably wrong to implement
> referential integrity actions like ON CASCADE DELETE in AFTER triggers.
> Seems to me that this breaks the fundamental rule of referential
> integrity: if B references A then there must always be a matching A
> row for every B row. Therefore, if we delete a row from A we should
> delete the matching B row(s) before, not after, we delete from A.
> Otherwise the remainder of the transaction sees an illegal state of
> the database.
If we're right in how we read the spec, then this isn't an illegal
state except for non-deferred constraints and then only for the
period between the delete and the after trigger running. Note:
I think we may be misinterpreting the spec here (more below),
but if our interpretation, deferred actions occur at end of transaction,
is correct, then the "invalid" state is valid to see for the rest of
transaction in that case.

> Comments? How about ON UPDATE actions?

However, I think that the intention was to have actions (obviously
other than NO ACTION) occur immediately even on deferred
constraints. I say this because the sections on figuring matching
and uniquely matching rows makes little sense if the action could be
deferred and IIRC it says things like "if a row is marked for removal"
rather than "at the time of checking a constraint, if a row was marked
for removal."

When I tried this in Oracle a while ago, this was also what they
did. A deferred constraint with a cascade would kill the
referencing rows after the delete so you wouldn't see them for the
rest of the transaction.

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Myers 2001-04-02 21:22:05 Re: Re: Changing the default value of an inherited column
Previous Message Bruce Momjian 2001-04-02 17:59:11 Update HISTORY/release.sgml