model-writtenrun 1592 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Bernice Southey reported that a data-modifying CTE inserting a GENERATED ALWAYS AS IDENTITY value fails when the outer query modifies an automatically updatable view, and proposed processing CTEs only at the top rewrite level in #1.
- Kirill Reshke questioned the approach and test choices in #2; Dean Rasheed argued that these queries should remain valid and repeated rewriting should be avoided in #3, while Tom Lane suggested investigating restoration of rewrite idempotency in #4.
- Dean demonstrated that the original guard skips necessary processing of CTEs introduced by rule actions in #7, and Tom explored separating CTE rewriting from the main recursion in #8.
- Dean supplied a replacement that tracks already-rewritten CTE names in #9, preferring a localized, backpatchable fix over broader restructuring because the original failure involves commonly used features.
- Bernice independently revised her original guard to suppress only view recursion in #10, but Dean showed that it still fails for an INSTEAD OF rule in #12, leaving that alternative unsuitable.
- Tom proposed tracking the number of processed CTEs instead of their names in #11, and Dean implemented that refinement in #14, relying on existing CTEs remaining at the end of the combined list.
- Tom approved the count-based version with suggestions to use foreach_current_index() and document the list-order dependency in #15, while Bernice requested broader rules coverage in #16.
- Dean committed 3881561d77 from #14 with those small code and comment edits and an expanded regression test combining rules, views, and multiple CTEs; he confirmed the changes and successful backpatching in #17 and #18, leaving the fix landed through PostgreSQL 14.