Re: rule causes nextval() to be invoked twice
От | Tom Lane |
---|---|
Тема | Re: rule causes nextval() to be invoked twice |
Дата | |
Msg-id | 10284.1058935315@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | rule causes nextval() to be invoked twice (paul cannon <pik@debian.org>) |
Список | pgsql-sql |
paul cannon <pik@debian.org> writes: > I'm having trouble understanding the behavior of rules with regards to > default values. > ... > If I remove the REFERENCES constraint, then I can see why. The insert > made into main behaves as expected; it gets nextval('main_id_seq'), > which comes out to 1. However, the main_insert rule gets _another_ > nextval('main_id_seq'), and the value 2 is inserted into othertable. Yeah. Rules are macros, and as such have the usual issues about multiple evaluations of arguments. Arguments with side effects are bad news. It looks to me like what you are trying to do is reflect a copy of an inserted row into a log table. You'd be better advised to do this with a trigger ... probably an AFTER trigger, so that you know exactly what got inserted. (BEFORE triggers have to consider the possibility that they're not the last BEFORE trigger.) regards, tom lane
В списке pgsql-sql по дате отправления: