map_from_arrays
从给定的键数组和值数组对创建一个 MAP 值。
此函数从 v3.1 版本开始支持。
语法
MAP map_from_arrays(ARRAY keys, ARRAY values)
参数
keys
: 用于构造结果 MAP 的键。 请确保键的元素是唯一的。values
: 用于构造结果 MAP 的值。
返回值
返回一个从输入键和值构造的 MAP。
- 键和值的长度必须相同,否则将返回错误。
- 如果键或值为 NULL,此函数返回 NULL。
- 返回的 MAP 值具有不同的键。
示例
select map_from_arrays([1, 2], ['Star', 'Rocks']);
+--------------------------------------------+
| map_from_arrays([1, 2], ['Star', 'Rocks']) |
+--------------------------------------------+
| {1:"Star",2:"Rocks"} |
+--------------------------------------------+
select map_from_arrays([1, 2], NULL);
+-------------------------------+
| map_from_arrays([1, 2], NULL) |
+-------------------------------+
| NULL |
+-------------------------------+
select map_from_arrays([1,3,null,2,null],['ab','cdd',null,null,'abc']);
+--------------------------------------------------------------------------+
| map_from_arrays([1, 3, NULL, 2, NULL], ['ab', 'cdd', NULL, NULL, 'abc']) |
+--------------------------------------------------------------------------+
| {1:"ab",3:"cdd",2:null,null:"abc"} |
+--------------------------------------------------------------------------+