📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

ARRAY_UNIQUE



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

Was this page helpful?