Skip to main content

ARRAY_SIZE

Description

Count the number of elements in an array

Aliases

  • SIZE
  • CARDINALITY

Syntax

ARRAY_SIZE(<arr>) 

Parameters

ParameterDescription
<arr>The array to be calculated

Return Value

Returns the number of elements in the array. If the input array is NULL, it returns NULL.

Example

SELECT ARRAY_SIZE(['a', 'b', 'c']),ARRAY_SIZE([NULL]),ARRAY_SIZE([]);
+------------------------------+---------------------+-----------------+
| cardinality(['a', 'b', 'c']) | cardinality([NULL]) | cardinality([]) |
+------------------------------+---------------------+-----------------+
| 3 | 1 | 0 |
+------------------------------+---------------------+-----------------+