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

From Fabien COELHO
Subject "strange" rule behavior with nextval on new.* fields
Date
Msg-id Pine.LNX.4.61.0411101005280.4884@sablons.cri.ensmp.fr
Whole thread Raw
Responses Re: "strange" rule behavior with nextval on new.* fields
Re: "strange" rule behavior with nextval on new.* fields
List pgsql-bugs
Dear debuggers,

I'd like to report the following "strange" behavior that I encountered
while trying (a bad idea, I know) to use a rule as a "poor man sql-trigger".

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".

As a consequence, my update does not work, i.e. new.id is actually
different from the id being used by the insert in the example so the
expected behavior that previous . [Note that even if it would work as I
expected, concurrent transaction could break the property.]

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.

In the attached file, the result of 4 inserts is:

  id | data  | islast
----+-------+--------
   1 | one   | f
   3 | two   | f
   6 | three | f
  10 | four  | f

last_val is 14

Where I would rather have expected:

  id | data  | islast
----+-------+--------
   1 | one   | f
   2 | two   | f
   3 | three | f
   4 | four  | t

last_val should be 4

Have a nice day,

--
Fabien.

pgsql-bugs by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: BUG #1310: libecpg.dll missing from msi package
Next
From: Andrew McMillan
Date:
Subject: Re: ALTER USER SET log_* not allowed...