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

From Richard Huxton
Subject Re: possible bug using combination of 'serial' and rule
Date
Msg-id 41864F71.7030105@archonet.com
Whole thread Raw
In response to possible bug using combination of 'serial' and rule  (Ralph Heinkel <ralph@strubi.ox.ac.uk>)
List pgsql-bugs
Ralph Heinkel wrote:
> Hi,
>
> I think this is a bug (I hope not a feature).
>
> Description:
> --------------------
> The table 'tmp' gets records added, and uses a serial to fill
> the attribute 'strorage_id'.  The table has a rule which logs
> all inserts into the table 'log'.
>
> Problem:
> ----------------
> 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'!!!
> You can see that the 'tmp' table only contains odd storage_ids,
> while the log table only contains even ones.

This is as expected (though perhaps not what you want). Rules are
basically macros, so you can end up with nextval() etc. being evaluated
multiple times.

For logging inserts, you want a trigger.

HTH

--
   Richard Huxton
   Archonet Ltd

pgsql-bugs by date:

Previous
From: Markus Bertheau
Date:
Subject: foreign key validation error message
Next
From: Michael Fuhr
Date:
Subject: Re: possible bug using combination of 'serial' and rule