Re: trigger before delete question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: trigger before delete question
Дата
Msg-id 1386.1240323224@sss.pgh.pa.us
обсуждение исходный текст
Ответ на trigger before delete question  (Sigrid Thijs <sigrid.thijs@gmail.com>)
Список pgsql-sql
Sigrid Thijs <sigrid.thijs@gmail.com> writes:
> I've bumped into a problem with a trigger before delete that I do not
> immediately understand. I have made a simple example that also illustrates
> the issue, but in reality the database structure is more complex.

The reason it doesn't work is that the delete from member cascades back
to update the club row (ie, set contact_member_id to null) and so by the
time the original delete is attempted the row version it's against is
already obsolete.  That results in nothing happening, not in re-issuing
the delete against the updated row version.

Personally I'd recommend rethinking this unholy mix of recursive foreign
keys and bad manual substitutes for foreign keys.  However, if you can't
come up with a less bogus schema design, you might find that it helps to
propagate information to derived rows in AFTER triggers rather than
BEFORE triggers.
        regards, tom lane


В списке pgsql-sql по дате отправления:

Предыдущее
От: Sigrid Thijs
Дата:
Сообщение: trigger before delete question
Следующее
От: ShuA
Дата:
Сообщение: Re[3]: Need a script that bakes INSERT script from SELECT results