Re: simple rule question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: simple rule question
Дата
Msg-id 9920.989686521@sss.pgh.pa.us
обсуждение исходный текст
Ответ на simple rule question  (Neil Conway <nconway@klamath.dyndns.org>)
Список pgsql-general
Neil Conway <nconway@klamath.dyndns.org> writes:
> I want to create a rule (or a trigger or whatever) so that when
> data is inserted into a certain table, one column of the
> newly inserted row is replaced with the result of a function.

I don't think you can do that with a rule; I see no way to write a
non-circular rule for it.  But it's easy with a trigger.  The trigger
function body would be something like

    new.specialcol := my_function(new.specialcol);
    return new;

and then you'd declare it as a BEFORE INSERT trigger.  (AFTER INSERT
is too late to change the contents of the to-be-inserted row.)

See the manual or past discussions of triggers for the syntactical
details.

            regards, tom lane

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

Предыдущее
От: "Gyozo Papp"
Дата:
Сообщение: about new join syntax performance
Следующее
От: Tom Lane
Дата:
Сообщение: Re: about new join syntax performance