Skip to main content
Aggregate · Window
The result ARRAY is non-NULL. NULL input values are retained as one distinct NULL element; all-NULL nonempty 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

  • COLLECT_SET always removes duplicates. For windows, use all rows in the group or a frame starting at its first row; sliding frames are not supported.
  • 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: ARRAY with the SQL type of value as its element type
  • NULL behavior: The result ARRAY is non-NULL. NULL input values are retained as one distinct NULL element; all-NULL nonempty input yields [NULL].
  • Empty input: Returns [] for an empty global aggregate or empty frame. An all-NULL nonempty group/frame returns [NULL].
  • Shape: One-dimensional array containing one element for each distinct input value, including at most one NULL.
  • Ordering: Element order is unspecified. WITHIN GROUP is accepted but currently does not apply its ordering; use ARRAY_SORT on the result when sorted values are needed.

Properties

Usage notes

  • Duplicate elimination is inherent; no DISTINCT keyword is needed.
  • COLLECT_SET retains a NULL element when any input is NULL. ARRAY_UNIQUE_AGG explicitly removes NULL instead.
  • To exclude NULL, filter the input with WHERE value IS NOT NULL before aggregation.
  • 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.
  • 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.
  • Duplicate values are removed whether or not you write DISTINCT. Repeated NULL values become one NULL; DISTINCT does not remove that NULL.

Examples

Distinct values including NULL, sorted

  • ARRAY_SORT orders ascending with NULL last.

All NULL values

Empty input

Filter NULL before collecting

  • WHERE removes NULL rows before aggregation.

Distinct values across all rows in each group

Sort distinct values and NULL

Limitations

  • WITHIN GROUP ordering is currently ignored. Sort the result with ARRAY_SORT for ascending values with NULL last.
  • Sliding frames that drop earlier rows and RANGE frames with numeric or time offsets are not supported.
  • IGNORE NULLS/RESPECT NULLS clauses are unsupported; filter the input to remove NULL.
Last modified on October 15, 2026