Re: Is this correct behavior for ON DELETE rule? - Mailing list pgsql-general

From Tom Lane
Subject Re: Is this correct behavior for ON DELETE rule?
Date
Msg-id 17290.1109374157@sss.pgh.pa.us
Whole thread Raw
In response to Is this correct behavior for ON DELETE rule?  ("Rick Schumeyer" <rschumeyer@ieee.org>)
Responses Re: Is this correct behavior for ON DELETE rule?  ("Rick Schumeyer" <rschumeyer@ieee.org>)
List pgsql-general
"Rick Schumeyer" <rschumeyer@ieee.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

pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Is this correct behavior for ON DELETE rule?
Next
From: Peter Eisentraut
Date:
Subject: Re: row numbering