Composite data type
Contents
Composite data type#
MAP type#
Represents values comprising a set of key-value pairs.
Syntax
MAP < KEY, VALUE >
Example
-- construct map value with map builtin function, each parameter is
-- key1, value1, key2, value2, ... respectively
select map (1, "12", 2, "100")
-- {1: "12", 2: "100"}
-- access map value with [] operator
select map (1, "12", 2, "100")[2]
-- "100"
Limitations
Generally not recommended to store a map value with too much key-value pairs, since it’s a row-based storage model.
Map data type can not used as the key or ts column of table index, queries can not be optimized based on specific key value inside a map column neither.
Query a key-value in a map takes
O(n)
complexity at most.Currently, it is not allowed to output a map type value from a SQL query, however you can access information about the map value using map-related expressions. For example, you may use
[]
operator over amap<int, int>
type to extract value of specific key.