Creates an array based on given values.
Syntax
array array(<value>, <value>[, ...])
Parameters
value: Required. A value of any data type. All values in the same call must be of the same data type.
Return value
Returns a value of the ARRAY type. The returned array contains one element per argument, in the same order as the arguments.
Usage notes
-
The number of elements in the returned array equals the number of arguments.
-
All arguments must share the same data type.
Examples
Example: Create an array from table columns
The t_table table has columns c1 (BIGINT), c2 (STRING), c3 (STRING), c4 (BIGINT), and c5 (BIGINT):
+------------+-----+-----+------------+------------+
| c1 | c2 | c3 | c4 | c5 |
+------------+-----+-----+------------+------------+
| 1000 | k11 | k21 | 86 | 15 |
| 1001 | k12 | k22 | 97 | 2 |
| 1002 | k13 | k23 | 99 | 1 |
+------------+-----+-----+------------+------------+
Create an array from the c2, c4, c3, and c5 columns:
SELECT array(c2, c4, c3, c5) FROM t_table;
Result:
+------+
| _c0 |
+------+
| [k11, 86, k21, 15] |
| [k12, 97, k22, 2] |
| [k13, 99, k23, 1] |
+------+
Related functions
array is a complex type function. For functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.