Re: "strange" rule behavior with nextval on new.* fields

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: "strange" rule behavior with nextval on new.* fields
Дата
Msg-id 20041112090332.GA12450@winnie.fuhr.org
обсуждение исходный текст
Ответ на "strange" rule behavior with nextval on new.* fields  (Fabien COELHO <coelho@cri.ensmp.fr>)
Ответы Re: "strange" rule behavior with nextval on new.* fields  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: "strange" rule behavior with nextval on new.* fields  (Fabien COELHO <fabien.coelho@ensmp.fr>)
Список pgsql-bugs
On Wed, Nov 10, 2004 at 10:23:41AM +0100, Fabien COELHO wrote:

> It seems that "on update do also" rules the new.* fields are evaluated
> several times instead of being computed once, which is a bad idea, esp.
> for "nextval".

This comes up often and the response is usually something like,
"Rules are macros, which is why referring to NEW.id causes another
evaluation of nextval().  If you don't want that to happen then use
a trigger."

> Anyway, it really looks like a strange behavior to me, so misleading and
> unexpected that it could be qualified as a bug rather than a feature. I
> did not spot such caveats by a quick look thru the documentation.

This comes up often enough that maybe it warrants a "Caveats with
Rules" section in "The Rule System" chapter and a link to that
section in the CREATE RULE documentation, as well as mention in the
FAQ.

Thoughts from the developers?  I'd offer to write the additional
documentation but my understanding of the rule system is pretty
shallow.  Nevertheless, maybe I could at least write something
that others could build on.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

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

Предыдущее
От: Fabien COELHO
Дата:
Сообщение: Re: "strange" rule behavior with nextval on new.* fields
Следующее
От: Tom Lane
Дата:
Сообщение: Re: "strange" rule behavior with nextval on new.* fields