Map(K, V)¶
Data type Map(K, V)
stores key-value pairs.
Unlike other databases, maps are not unique in Tinybird: a map can contain two elements with the same key. The reason for that is that maps are internally implemented as Array(Tuple(K, V))
.
You can use use the syntax m[k]
to obtain the value for key k
in map m
. Also, m[k]
scans the map, for example the runtime of the operation is linear in the size of the map.
### Parameters
K
is the type of the Map keys. Arbitrary type except Nullable and LowCardinality nested with Nullable types.V
is the type of the Map values. Arbitrary type.
Convert tuple to map¶
Values of type Tuple()
can be cast to values of type Map()
using function CAST:
Example
Query:
SELECT CAST(([1, 2, 3], ['Ready', 'Steady', 'Go']), 'Map(UInt8, String)') AS map;
Result:
┌─map───────────────────────────┐ │ {1:'Ready',2:'Steady',3:'Go'} │ └───────────────────────────────┘
Reading subcolumns of map¶
To avoid reading the entire map, you can use subcolumns keys
and values
in some cases.