Re: "strange" rule behavior with nextval on new.* fields - Mailing list pgsql-bugs

From Michael Fuhr
Subject Re: "strange" rule behavior with nextval on new.* fields
Date
Msg-id 20041112090332.GA12450@winnie.fuhr.org
Whole thread Raw
In response to "strange" rule behavior with nextval on new.* fields  (Fabien COELHO <coelho@cri.ensmp.fr>)
Responses Re: "strange" rule behavior with nextval on new.* fields
Re: "strange" rule behavior with nextval on new.* fields
List 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 by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: "strange" rule behavior with nextval on new.* fields
Next
From: Tom Lane
Date:
Subject: Re: "strange" rule behavior with nextval on new.* fields