Categories:

Semi-structured and Structured Data Functions (Map)

MAP_CAT¶

Returns the concatenatation of two MAPs.

Syntax¶

MAP_CAT( <map1> , <map2> )
Copy

Arguments¶

map1

The source MAP.

map2

The MAP to be appended to map1.

Returns¶

The return type of this function is the type of map1. map2 is coerced into the map1 type following the coercion rules. For information about coercion rules, see Implicit Casting a Value (Coercion).

Usage Notes¶

  • If both map1 and map2 have a value with the same key, then the output map contains the value from map2.

  • If either argument is NULL, the function returns NULL without reporting any error.

Examples¶

Create two MAPs and concatenate them:

SELECT MAP_CAT(
  {'map1key1':'map1value1','map1key2':'map1value2'}::MAP(VARCHAR,VARCHAR),
  {'map2key1':'map2value1','map2key2':'map2value2'}::MAP(VARCHAR,VARCHAR))
  AS concatenated_maps;
Copy
+-----------------------------+
| CONCATENATED_MAPS           |
|-----------------------------|
| {                           |
|   "map1key1": "map1value1", |
|   "map1key2": "map1value2", |
|   "map2key1": "map2value1", |
|   "map2key2": "map2value2"  |
| }                           |
+-----------------------------+