Forest Wilkinson <fspam@home.com> writes:
> What's going on here? My rule inserted a new row into bar, but the fooid
> it used was not the new value inserted into foo. It looks like my rule is
> inserting "nextval('foo_fooid_seq')" into the bar table, rather than
> inserting the new primary key from the foo table. Is this the intended
> behavior?
NEW and OLD are effectively macros, not variables. So yes, you get
extra evaluations of nextval() this way. I think there are cases where
that is actually what you want (not in this case obviously :-(). It
would be fairly difficult to change, anyway.
> How can I get the result I want?
If you want to copy the data actually inserted, a trigger is a much
better bet than a rule.
regards, tom lane