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

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Bugs List <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: "strange" rule behavior with nextval on new.* fields
Date: 2004-11-12 09:03:32
Message-ID: 20041112090332.GA12450@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Fabien COELHO 2004-11-12 09:39:50 Re: "strange" rule behavior with nextval on new.* fields
Previous Message Fabien COELHO 2004-11-12 07:30:34 Re: "strange" rule behavior with nextval on new.* fields