Re: After Insert or Update Trigger Issues!

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: After Insert or Update Trigger Issues!
Дата
Msg-id 4356.1111975312@sss.pgh.pa.us
обсуждение исходный текст
Ответ на After Insert or Update Trigger Issues!  (Kyrill Alyoshin <kyrill@technolog.ca>)
Список pgsql-general
Kyrill Alyoshin <kyrill@technolog.ca> writes:
> 1. MY FUNCTIONS

> CREATE OR REPLACE FUNCTION insert_stamp() RETURNS TRIGGER AS
> $audit_insert$
>     BEGIN
>         NEW.created_ts := 'now';
>         NEW.updated_ts := 'now';
>         RETURN NEW;
>     END;
> $audit_insert$ LANGUAGE plpgsql;

Do you understand the difference between a BEFORE trigger and an AFTER
trigger?  An AFTER trigger fires *after* the operation is done.
Therefore it can't affect the data that was stored.  It's no surprise
that the above is a no-op when used as an AFTER trigger; it's just
modifying a row in memory that will be thrown away afterwards.

Usually AFTER triggers are used to propagate data to other tables;
in that scenario, what you want is precisely to know what the final
state of the row is, after all the BEFORE triggers got done doing their
things.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: plpgsql no longer exists
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: After Insert or Update Trigger Issues!