Aggregate · Window
NULL values are ignored.
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
- Use a frame that includes all rows in the group or starts at the first row (
UNBOUNDED PRECEDING). Sliding frames that drop earlier rows are not supported. RANGE frames with a numeric or time offset are not supported.
Arguments
Aggregate and window
Returns
- Type: BIGINT
- NULL behavior: NULL values are ignored.
- Empty input: Returns zero on empty input.
Properties
- Approximation bound: Standard error is 0.8125%. This describes typical statistical variation, not a guaranteed maximum error.
Usage notes
- TINYINT and SMALLINT inputs return an exact count. Counts for other supported types are estimates.
- All floating-point NaN values count as one distinct value. Positive and negative zero also count as the same value.
- 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.
Examples
Count distinct non-NULL values
There are two distinct non-NULL values: 1 and 2. SMALLINT inputs are counted exactly.
Count distinct strings per group
These small groups produce the counts shown; the function estimates counts for larger inputs.
Limitations
- The error level is fixed. An argument to configure relative standard deviation is not accepted.
- Sliding windows that drop earlier rows are not supported. Start the frame at the first row in the group.
- ARRAY, MAP, and STRUCT inputs are not supported.
Last modified on October 15, 2026