Removes duplicate elements from Array a.

Syntax

array<T> array_distinct(array<T> <a>)

Parameters

a: required. This parameter specifies an array that T in array<T> specifies the data type of the elements in the array. The elements can be of any data type.

Return value

A value of the ARRAY type is returned. The return value varies based on the following rules:
  • The returned array has no duplicate elements, and the elements are sorted in the same order as Array a.
  • If an element in Array a is null, the null element is involved in the operation.
  • If the input array is empty, an empty array is returned.

Examples

  • Example 1: Remove duplicate elements from array(10, 20, 30, 30, 20, 10). Sample statement:
    -- [10,20,30] is returned. 
    select array_distinct(array(10, 20, 30, 30, 20, 10));
  • Example 2: Remove duplicate elements from array(10, 20, 20, null, null, 30, 20, null). Sample statement:
    -- [10,20,null,30] is returned. 
    select array_distinct(array(10, 20, 20, null, null, 30, 20, null)); 
  • Example 3: The array is empty. Sample statement:
    -- [] is returned. 
    select array_distinct(array());