Skip to main content

ARRAY_UNIQUE

Introduced or updated: v1.2.762

Returns the number of unique elements in the array.

Syntax

ARRAY_UNIQUE(array)

Parameters

ParameterDescription
arrayThe array to analyze for unique elements.

Return Type

INTEGER

Notes

This function works with both standard array types and variant array types.

Examples

Example 1: Counting Unique Elements in a Standard Array

SELECT ARRAY_UNIQUE([1, 2, 2, 3, 3, 3]);

Result:

3

Example 2: Counting Unique Elements in a Variant Array

SELECT ARRAY_UNIQUE(PARSE_JSON('["apple", "banana", "apple", "orange", "banana"]'));

Result:

3

Example 3: Empty Array

SELECT ARRAY_UNIQUE([]);

Result:

0