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
---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match