> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# map_concat

> 将多个 Map 合并成一个 Map，重复 Key 保留最后一个。

将多个 Map 合并成一个 Map。如果多个 Map 中都存在 Key 值相同的键值对，该函数仅保留最后一个出现的键值对（LAST WIN 原则）。比如，`SELECT map_concat(map{1:3},map{1:'4'});` 返回 `{1:"4"}`。

该函数从 3.1 版本开始支持。

## 语法

```Haskell theme={null}
ANY_MAP map_concat(any_map0, any_map1...)
```

## 参数说明

`any_mapN`: 待合并的 Map。多个 Map 的数据类型必须兼容。如果 Map 的数据类型不同，该函数会返回一个通用类型 (supertype)。

## 返回值说明

返回一个 Map，包含所有合并后的键和值。

## 示例

```Plain theme={null}
mysql> SELECT map_concat(map('a',1, 'b',2), map('c',3));
+------------------------------------------+
| map_concat(map{'a':1,'b':2}, map{'c':3}) |
+------------------------------------------+
| {"c":3,"a":1,"b":2}                      |
+------------------------------------------+

mysql> select map_concat(map{1:3},map{'3.323':3});
+--------------------------------------+
| map_concat(map{1:3}, map{'3.323':3}) |
+--------------------------------------+
| {"3.323":3,"1":3}                    |
+--------------------------------------+


mysql> select map_concat(map{1:3},map{1:'4', 3:'5',null:null}, null);
+--------------------------------------------------------+
| map_concat(map{1:3}, map{1:'4',3:'5',NULL:NULL}, NULL) |
+--------------------------------------------------------+
| {null:null,1:"4",3:"5"}                                |
+--------------------------------------------------------+
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.