Re: possible bug using combination of 'serial' and rule

From: Richard Huxton <dev(at)archonet(dot)com>
To: ralph(dot)heinkel(at)web(dot)de
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: possible bug using combination of 'serial' and rule
Date: 2004-11-01 15:00:01
Message-ID: 41864F71.7030105@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Fuhr 2004-11-01 15:12:49 Re: possible bug using combination of 'serial' and rule
Previous Message Markus Bertheau 2004-11-01 14:38:19 foreign key validation error message