Expand description
Built-in window functions (S13.5, bd-14i6).
Implements: row_number, rank, dense_rank, percent_rank, cume_dist, ntile, lag, lead, first_value, last_value, nth_value, plus aggregate-as-window variants including group_concat and string_agg.
These functions implement the WindowFunction trait. The VDBE is
responsible for partitioning, ordering, and frame management; these
implementations provide the per-row computation logic.
§Design Notes
Pure-numbering functions (row_number, rank, dense_rank) track position via step() and expose the current value through value(). The ORDER BY column is passed as args[0] so the function can detect peer-group boundaries.
Buffer-based functions (lag, lead, first_value, last_value, nth_value) maintain an internal VecDeque of values and expose frame-relative access through value().
Structs§
- Cume
Dist Func - Cume
Dist State - State for
cume_dist(). - Dense
Rank Func - Dense
Rank State - First
Value Func - First
Value State - LagFunc
- LagState
- State for
lag(): maintains a buffer of previous values. - Last
Value Func - Last
Value State - Lead
Func - Lead
State - State for
lead(): maintains a buffer and reads ahead. - NthValue
Func - NthValue
State - Ntile
Func - Ntile
State - State for
ntile(N). - Percent
Rank Func - Percent
Rank State - State for
percent_rank(). - Rank
Func - Rank
State - RowNumber
Func - RowNumber
State - Window
AvgFunc - Window
AvgState - Window
Count Func - Window
Count State - Window
Group Concat Func - Window
Group Concat State - Window
MaxFunc - Window
MaxState - Window
MinFunc - Window
MinState - Window
String AggFunc - Window
SumFunc - Window
SumState - Window
Total Func
Functions§
- cmp_
values - Compare two SQLite values using type-aware ordering.
- register_
window_ builtins - Register all S13.5 window functions.