paul cannon <[EMAIL PROTECTED]> 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 ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly