Commit c2717eb
authored
fix: only merge already-computed aggregates when select? is true (#193)
Fixes a GROUP BY error introduced in bb458d5 where already-computed
aggregates were being merged into the SELECT clause unconditionally.
When aggregates filter on nested first aggregates the nested aggregate
was incorrectly added to the SELECT clause in GROUP BY contexts,
causing PostgreSQL grouping_error "column must appear in the GROUP BY
clause or be used in an aggregate function"
The fix adds a select? guard to only merge already-computed aggregates
when we're in a select context. In internal subqueries with GROUP BY,
aggregates remain available in bindings for FILTER clauses without
being selected, avoiding the conflict.
A test demonstrating the bug was added to ash_postgres/test/aggregate_test.exs
test "multiple aggregates filtering on nested first aggregate"1 parent f6e2028 commit c2717eb
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
0 commit comments