model-writtenrun 4650 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Anban Company reported that equivalent queries using a CTE or a table triggered assertions in nodeAgg.c and execExprInterp.c on PostgreSQL 15.2 #1.
- Tom Lane simplified the query and explained that its innermost AVG belongs to the outer query level, making it an illegal nested aggregate that PostgreSQL 10 rejected but later versions allowed into execution #2.
- Tom clarified that the parser defect predated the executor changes: removing an execution-time check had exposed the incorrect assumption that a lower-level aggregate could not contain aggregates belonging to outer levels #3.
- Tom attached a patch that makes check_agg_arguments_walker() descend into aggregate arguments and adds a regression test expecting the nested-aggregate error; this was the thread's final message, with no subsequent review or testing response #3.
- Tom committed the attached patch unchanged later that day as 30dbdbe753, with backports to all supported branches, completing the fix proposed in #3.