Re: possible bug using combination of 'serial' and rule - Mailing list pgsql-bugs

From Michael Fuhr
Subject Re: possible bug using combination of 'serial' and rule
Date
Msg-id 20041101151249.GB18231@winnie.fuhr.org
Whole thread Raw
In response to possible bug using combination of 'serial' and rule  (Ralph Heinkel <ralph@strubi.ox.ac.uk>)
List pgsql-bugs
On Sun, Oct 31, 2004 at 03:37:26PM +0000, Ralph Heinkel wrote:
>
> I think this is a bug (I hope not a feature).

It's a feature.

> For each insert into table 'tmp' the serial counter is increased
> twice, once to create the entry in 'tmp', once for 'log'. The problem
> is that the rule does not see the correct 'storage_id'!!!

Rules are macros, so when you refer to NEW.storage_id in the rule
then the default expression "nextval('tmp_storage_id_seq')" is
evaluated again.  If you don't want that to happen then use a
trigger.

This comes up often -- maybe somebody could add it to the FAQ.

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

pgsql-bugs by date:

Previous
From: Richard Huxton
Date:
Subject: Re: possible bug using combination of 'serial' and rule
Next
From: Gaetano Mendola
Date:
Subject: Re: Not a real bug, but an error