I wrote: > That semantic issue doesn't get any less pressing just because the query > was generated by rewrite. So I now think that what we have to do is > throw an error if we have a modifying CTE and sub_action is different > from rule_action. Not quite sure how to phrase the error though.
Another idea that'd avoid disallowing functionality is to try to attach the CTEs to the rule_action not the sub_action. This'd require adjusting ctelevelsup in appropriate parts of the parsetree when those are different, so it seems like it'd be a pain. I remain unconvinced that it's worth it. regards, tom lane