Re: Preventing Deletions with triggers

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Preventing Deletions with triggers
Дата
Msg-id 4042.1085153332@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Preventing Deletions with triggers  (Jeff Post <POSTJL@milwaukee.k12.wi.us>)
Список pgsql-sql
Jeff Post <POSTJL@milwaukee.k12.wi.us> writes:
> CREATE or replace FUNCTION person_fake_delete() RETURNS TRIGGER AS '
>      BEGIN
>          OLD.status := 1; -- This does the fake deletion
>          RETURN NULL;  -- I thought this would prevent the delete from 
> actually happening.
>      END;
> ' LANGUAGE 'plpgsql';

> create trigger person_fake_delete
> before delete on person
> for each row EXECUTE PROCEDURE
> person_fake_delete();

> This however does not work.  the tupple is still deleted from the 
> table.    Any Ideas?

It works for me, in the sense that returning NULL prevents the
deletion.  However that assignment to OLD is a no-op: you can't change
the tuple that way.  You'd have to do something like
UPDATE person SET status = 1 WHERE key = OLD.key;

("key" being whatever your primary key for the table is)
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Problem with JOINS
Следующее
От: "Alexander M. Pravking"
Дата:
Сообщение: Memory usage on subselect