Skip to main content
Version: V1.0.0

Map constructor functions

Map constructor functions and operators are used to construct a map data type. seekdb currently supports the map() function and the {} operator.

map

The map() function is used to construct a map data type. The syntax is as follows:

map(key1, value1, key2, value2, ..., keyN, valueN)

The input parameters are described as follows:

  • The number of input parameters must be even. Parameters with odd indices are used to construct the key array, and parameters with even indices are used to construct the value array.
  • The data element types of key1keyN and value1valueN are described in Overview of map data types.
  • Note that the keys in the input key-value pairs must be unique. If there are duplicate keys, the value that comes later will overwrite the previous one.

The return value is a map data type (MAP).

Here are some examples:

-- Construct a map with one key-value pair, where the key is 1 and the value is 2.
SELECT map(1,2);
+----------+
| map(1,2) |
+----------+
| {1:2} |
+----------+
1 row in set (0.001 sec)
-- Construct a map with three key-value pairs.
SELECT map(1,"a",2,"b",3,"c");
+------------------------+
| map(1,"a",2,"b",3,"c") |
+------------------------+
| {1:"a",2:"b",3:"c"} |
+------------------------+
1 row in set (0.001 sec)
-- The data type of the key array is determined by the parameters with odd indices, and the data type of the value array is determined by the parameters with even indices.
SELECT map(1,"a","b",1.8,"ccc",3);
+-------------------------------+
| map(1,"a","b",1.8,"ccc",3) |
+-------------------------------+
| {"1":"a","b":"1.8","ccc":"3"} |
+-------------------------------+