Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-general by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group