Re: Is this correct behavior for ON DELETE rule?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Rick Schumeyer" <rschumeyer(at)ieee(dot)org>
Cc: "'PgSql General'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Is this correct behavior for ON DELETE rule?
Date: 2005-02-25 23:29:17
Message-ID: 17290.1109374157@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Rick Schumeyer" <rschumeyer(at)ieee(dot)org> writes:
> -- delete to item and book instead of bookview
> create rule bookviewdel as on delete to bookview do instead (
> delete from book where id=old.id;
> delete from item where id=old.id;
> );

This is an ancient gotcha: as soon as you delete the book row, there is
no longer any such entry in the bookview view ... and "old.id" is
effectively a reference to the bookview view, so the second delete
finds no matching rows.

If you can reasonably turn the view into a LEFT JOIN in one direction or
the other, then a workaround is to delete from the nullable side first.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2005-02-26 00:10:33 Re: row numbering
Previous Message Bruce Momjian 2005-02-25 23:22:56 Re: Is this correct behavior for ON DELETE rule?