You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Window aggregates read the output row: SUM(v) OVER (PARTITION BY g) gives 0 when v is not selected #2689
SUM, COUNT, AVG, MIN and MAX with OVER (PARTITION BY …) read the partition and the value from the output row by name. When the column is not in the SELECT list under its own name, or the argument is an expression, the result is wrong and there is no error.
Measured on develop (94ccf84), data g, v: ('x', 1), ('x', 2), ('y', 5), next to SQLite 3.43:
Query
AlaSQL
SQLite
SELECT g, v, SUM(v) OVER (PARTITION BY g) AS s
3, 3, 5
3, 3, 5
SELECT v, SUM(v) OVER (PARTITION BY g) AS s (no g in the list)
8, 8, 8
3, 3, 5
SELECT g, SUM(v) OVER (PARTITION BY g) AS s (no v in the list)
0, 0, 0
3, 3, 5
SELECT g, v AS val, SUM(v) OVER (PARTITION BY g) AS s
0, 0, 0
3, 3, 5
SELECT g, v, SUM(v * 2) OVER (PARTITION BY g) AS s
0, 0, 0
6, 6, 10
Cause
yy.Select.compile (src/40select.js, from #2411) computes the window aggregates after the SELECT list is built, from res[i][columnid]: the output row, and only a plain column name. The source row and the compiled expression are not used.
Direction
Compute the partition key and the argument from the source row with the compiled expressions, the way the SELECT list itself is computed, then attach the result to the output row. Nobody can rely on 0 or a sum over all partitions here, so this can go into 4.x.
The window's own ORDER BY (a running sum) is not applied either; that is the same gap as #2591, which is in 5.0.
Activity
mateuscmtropical commentedon Nov 11, 2026
Hi, I'd like to work on this one.
mateuscmtropical commentedon Nov 11, 2026
Hi, I've opened a PR for this: #3052