ARRAY_DISTINCT()
All functions > ARRAY > ARRAY_DISTINCT()
Returns an array with distinct elements, in order of first occurrence.
Signatures
Returns: An array with distinct elements in order of first occurrence
ARRAY_DISTINCT(array: ARRAY<T>) → ARRAY<T> sql
| Parameter | Type | Required | Description |
|---|---|---|---|
array | ARRAY<T> | Yes | The input array containing possible duplicate elements |
Notes
- Removes later duplicates and keeps the first occurrence of each element
- NULL stays one member, at the position of its first occurrence
- Eliminates all duplicates using set semantics
- Handles NULL values consistently
- Empty arrays remain empty
- Supports
ARRAY<ROW>andARRAY<ARRAY<T>>: equality is structural (exact field names, types, and values)
Availability
| Status | Backends |
|---|---|
| Not available | mysql |
Aliases
ARRAY_UNIQUE
See also
Examples
Rows
FeatureQL
RETURN
-- Remove duplicate numbers
f1 := ARRAY_DISTINCT(ARRAY(1, 2, 2, 3, 3, 3)),
-- Remove duplicate strings
f2 := ARRAY_DISTINCT(ARRAY('A', 'B', 'A', 'C', 'B')),
-- Real-world string example
f3 := ARRAY_DISTINCT(ARRAY('apple', 'banana', 'apple')),
-- No duplicates to remove
f4 := ARRAY_DISTINCT(ARRAY(1, 2, 3)),
-- All elements the same
f5 := ARRAY_DISTINCT(ARRAY(5, 5, 5)),
-- Empty array
f6 := ARRAY_DISTINCT(ARRAY()::ARRAY<BIGINT>)
;Result
| f1 ARRAY | f2 ARRAY | f3 ARRAY | f4 ARRAY | f5 ARRAY | f6 ARRAY |
|---|---|---|---|---|---|
| [1, 2, 3] | [A, B, C] | [apple, banana] | [1, 2, 3] | [5] | [] |