size (cardinality)
Description
Syntax
BIGINT size(ARRAY<T> arr)
BIGINT cardinality(ARRAY<T> arr)
This function returns the number of elements in the array. If the input array is null, it will return null.
Note:
It is only supported in vectorized engine.
Example
mysql> set enable_vectorized_engine=true;
mysql> select k1,k2,size(k2) from array_test;
+------+-----------+------------+
| k1 | k2 | size(`k2`) |
+------+-----------+------------+
| 1 | [1, 2, 3] | 3 |
| 2 | [] | 0 |
| 3 | NULL | NULL |
+------+-----------+------------+
mysql> select k1,k2,cardinality(k2) from array_test;
+------+-----------+-------------------+
| k1 | k2 | cardinality(`k2`) |
+------+-----------+-------------------+
| 1 | [1, 2, 3] | 3 |
| 2 | [] | 0 |
| 3 | NULL | NULL |
+------+-----------+-------------------+
Keywords
SIZE, CARDINALITY