Returns all keys in a MAP as an array.
Syntax
array<K> map_keys(map<K, V> <a>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
a | Yes | map<K, V> | A MAP value. K and V are the key type and value type of the map. |
Return value
Returns an array<K> containing the keys of the input map.
If the input map is null, null is returned.
Examples
Query with table data
The following example returns all keys from the t_map column in the t_table_map table.
Table schema and data:
+------+---------------------------+
| c1 | t_map |
+------+---------------------------+
| 1000 | {k11:86, k21:15} |
| 1001 | {k12:97, k22:2} |
| 1002 | {k13:99, k23:1} |
+------+---------------------------+c1 is of type BIGINT. t_map is of type MAP<STRING, BIGINT>.
-- Return the keys in the t_map column as an array.
SELECT c1, map_keys(t_map) FROM t_table_map;Output:
+------+------------+
| c1 | _c1 |
+------+------------+
| 1000 | [k11, k21] |
| 1001 | [k12, k22] |
| 1002 | [k13, k23] |
+------+------------+Related functions
MAP_KEYS is a complex type function. For all functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.