Re: Is this correct behavior for ON DELETE rule?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Is this correct behavior for ON DELETE rule?
Дата
Msg-id 17290.1109374157@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Is this correct behavior for ON DELETE rule?  ("Rick Schumeyer" <rschumeyer@ieee.org>)
Ответы Re: Is this correct behavior for ON DELETE rule?  ("Rick Schumeyer" <rschumeyer@ieee.org>)
Список 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 по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Is this correct behavior for ON DELETE rule?
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: row numbering