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

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: possible bug using combination of 'serial' and rule
Дата
Msg-id 41864F71.7030105@archonet.com
обсуждение исходный текст
Ответ на possible bug using combination of 'serial' and rule  (Ralph Heinkel <ralph@strubi.ox.ac.uk>)
Список 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 по дате отправления:

Предыдущее
От: Markus Bertheau
Дата:
Сообщение: foreign key validation error message
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: possible bug using combination of 'serial' and rule