Skip to content

fix(dialect): the n-th value is an aggregate over the group's rows - #67

Merged
stbischof merged 1 commit into
mainfrom
fix/nth-value-per-group
Oct 16, 2026
Merged

stbischof merged 1 commit into
mainfrom
fix/nth-value-per-group

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

NTH_VALUE(col, n) OVER (ORDER BY ...) in a grouped query runs over the groups, not over the rows of each group, so a cell showed the values of other members.

  • DuckDB picks the n-th element of an ordered list; PostgreSQL and H2 of an ordered ARRAY_AGG; nulls are filtered when asked.
  • ClickHouse, MySQL, Oracle and SQL Server have no ordered array aggregate here and refuse the measure instead of answering wrong.
  • New DuckDbNthValueTest.

Note: the tutorial check suite measure.aggregator.nth in rolap.mapping still expects the old window values.

NTH_VALUE ran as a window over the groups and showed other members' values.
Dialects without an ordered array aggregate refuse the measure.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant