Array(T)
An array of T
-type items, with the starting array index as 1. T
can be any data type, including an array.
Creating an Array
You can use a function to create an array:
You can also use square brackets.
Example of creating an array:
Working with Data Types
When creating an array on the fly, ClickHouse automatically defines the argument type as the narrowest data type that can store all the listed arguments. If there are any Nullable or literal NULL values, the type of an array element also becomes Nullable.
If ClickHouse couldn't determine the data type, it generates an exception. For instance, this happens when trying to create an array with strings and numbers simultaneously (SELECT array(1, 'a')
).
Examples of automatic data type detection:
If you try to create an array of incompatible data types, ClickHouse throws an exception:
Array Size
It is possible to find the size of an array by using the size0
subcolumn without reading the whole column. For multi-dimensional arrays you can use sizeN-1
, where N
is the wanted dimension.
Example
Query:
Result:
Reading nested subcolumns from Array
If nested type T
inside Array
has subcolumns (for example, if it's a named tuple), you can read its subcolumns from an Array(T)
type with the same subcolumn names. The type of a subcolumn will be Array
of the type of original subcolumn.
Example