Re: Referential Integrity

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Referential Integrity
Дата
Msg-id 5191.1044889792@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Referential Integrity  ("Alexander Stanier" <alexander.stanier@egsgroup.com>)
Ответы Re: Referential Integrity  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Список pgsql-sql
"Alexander Stanier" <alexander.stanier@egsgroup.com> writes:
> [ expected ON DELETE CASCADE doesn't seem to happen in this context: ]

> CREATE FUNCTION test() RETURNS INT4 AS '
> DECLARE
>     v_return INTEGER;
> BEGIN
>   DELETE FROM alex
>         WHERE aid =3D ''1''
>           AND bid =3D ''1'';

>   INSERT INTO alex (aid,bid,itemdesc)
>             VALUES (''1'',''1'',''OneOne'');

>   INSERT INTO alexette (aid,bid,vcode)
>                 VALUES (''1'',''1'',''V'');

>   RETURN 0;
> END;
> ' LANGUAGE 'plpgsql';

The cascaded deletes will be implemented at end of statement --- which
I believe is always taken to be the end of the current interactive
statement, ie, the "SELECT test()" you typed.  So they haven't happened
yet at the time the function tries to do the inserts.

This is probably a bug, but IIRC, it's not entirely obvious what to do
instead. I seem to recall some inconclusive discussions in pgsql-hackers
about designing a better rule for when to fire the RI actions.  Check
the list archives for details.
        regards, tom lane


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

Предыдущее
От: greg@turnstep.com
Дата:
Сообщение: Re: How to delete duplicate record
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: Referential Integrity