Re: BUG #1175: insert rule action with defaults

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #1175: insert rule action with defaults
Дата
Msg-id 9196.1087870493@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #1175: insert rule action with defaults  ("PostgreSQL Bugs List" <pgsql-bugs@postgresql.org>)
Ответы Re: BUG #1175: insert rule action with defaults
Список pgsql-bugs
"PostgreSQL Bugs List" <pgsql-bugs@postgresql.org> writes:
> [ double evaluation of serial-column default with ]
>
> create rule silly_insert_r as on insert to silly do
> insert into action (item_id,whence)
> values (new.id,'now');

The standard answer to this is "use a trigger, not a rule, to copy
inserted or updated data to another table".  A rule is basically a
macro and as such has the usual multiple-evaluation hazards that
all C programmers are familiar with :-(.  There are times when this
behavior is just what you want, but not when trying to copy the
results of volatile expressions.

People are often scared away from triggers because of the apparent
notational complexity.  This is too bad, because conceptually triggers
are *much* simpler than rules.  Someday I'd like to rewrite the docs
so that triggers are discussed first and made to look like the simpler
facility ...

            regards, tom lane

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

Предыдущее
От: "PostgreSQL Bugs List"
Дата:
Сообщение: BUG #1175: insert rule action with defaults
Следующее
От: Michael Meskes
Дата:
Сообщение: Re: BUG #1164: Informix compatibility ecpg