Aggregate · Window
Aliases: last_value
RESPECT NULLS is default. IGNORE NULLS selects a non-NULL boundary value; all-NULL input yields NULL.
Syntax
A window function keeps each input row and adds a result for that row. PARTITION BY groups rows with matching values; without it, all input rows form one group.
Aggregate
Window
Arguments
Aggregate and window
Returns
- Type: same SQL type as value
- NULL behavior: RESPECT NULLS is default. IGNORE NULLS selects a non-NULL boundary value; all-NULL input yields NULL.
- Empty input: Returns NULL on empty input/frame.
Properties
Usage notes
- Grouped input order is unspecified; use a unique ordering key for stable window results.
- INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
- Query tools may report a DECIMAL result as DOUBLE or a TIME result as INTEGER. The returned value still keeps its decimal precision and scale, or its time type. A reported type does not convert the value.
- Supports DISTINCT: Adding DISTINCT does not remove duplicate input values.
Examples
Basic example
All rows and running results, with NULL handling
Limitations
- RANGE frames with a numeric or time offset are not supported.
- In grouped calls, DISTINCT does not remove duplicate input values. Selection can still vary when rows are tied or their order changes.
- The optional Boolean shorthand on LAST is outside these calling forms; use the explicit one-argument function and NULL-treatment clause.
Last modified on October 15, 2026