Back to Starrocks

array_length

docs/en/sql-reference/sql-functions/array-functions/array_length.md

4.1.01.1 KB
Original Source

array_length

Returns the number of elements in an array. The result type is INT. If the input parameter is NULL, the result is also NULL. Null elements are counted in the length.

It has an alias cardinality().

Syntax

Haskell
INT array_length(any_array)

Parameters

any_array: the ARRAY value from which you want to retrieve the number of elements.

Return value

Returns an INT value.

Examples

plain
mysql> select array_length([1,2,3]);
+-----------------------+
| array_length([1,2,3]) |
+-----------------------+
|                     3 |
+-----------------------+
1 row in set (0.00 sec)

mysql> select array_length([1,2,3,null]);
+-------------------------------+
| array_length([1, 2, 3, NULL]) |
+-------------------------------+
|                             4 |
+-------------------------------+

mysql> select array_length([[1,2], [3,4]]);
+-----------------------------+
| array_length([[1,2],[3,4]]) |
+-----------------------------+
|                           2 |
+-----------------------------+
1 row in set (0.01 sec)

keywords

ARRAY_LENGTH, ARRAY, CARDINALITY