ARRAY_DISTINCT

All functions > ARRAY > ARRAY_DISTINCT

Returns an array with distinct elements, sorted in ascending order.

Signatures

Returns: An array with distinct elements sorted in ascending order

ARRAY_DISTINCT(array: ARRAY<T>) → ARRAY<T>
sql
ParameterTypeRequiredDescription
arrayARRAY<T>YesThe input array containing possible duplicate elements

Notes

  • Removes all duplicate elements and sorts the result
  • Returns sorted distinct elements
  • Eliminates all duplicates using set semantics
  • Handles NULL values consistently
  • Empty arrays remain empty

Aliases

  • ARRAY_UNIQUE

Examples

FeatureQL
SELECT
    f1 := ARRAY_DISTINCT(ARRAY[1, 2, 2, 3, 3, 3]),  -- Remove duplicate numbers
    f2 := ARRAY_DISTINCT(ARRAY['A', 'B', 'A', 'C', 'B']),  -- Remove duplicate strings
    f3 := ARRAY_DISTINCT(ARRAY['apple', 'banana', 'apple']),  -- Real-world string example
    f4 := ARRAY_DISTINCT(ARRAY[1, 2, 3]),  -- No duplicates to remove
    f5 := ARRAY_DISTINCT(ARRAY[5, 5, 5]),  -- All elements the same
    f6 := ARRAY_DISTINCT(ARRAY[]::BIGINT[])  -- Empty array
;
Result
f1 ARRAYf2 ARRAYf3 ARRAYf4 ARRAYf5 ARRAYf6 ARRAY
[1, 2, 3][A, B, C][apple, banana][1, 2, 3][5][]

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19