Mapping operations
A mapping operation function performs basic operations, such as extracting the key or value element, on the input mapping data, and then returns the mapping data after the operation. At present, seekdb supports two mapping operation functions: map_keys() and map_values().
map_keys
The map_keys() function returns a list of keys in the target mapping. Its syntax is as follows:
map_keys(map)
The input parameters must be mapping data.
The return value is an array.
As follows:
SELECT map_keys(map(1,"apple",2,"banana"));
+-------------------------------------+
| map_keys(map(1,"apple",2,"banana")) |
+-------------------------------------+
| [1,2] |
+-------------------------------------+
1 row in set (0.001 sec)
CREATE TABLE t1 (
id INT NOT NULL AUTO_INCREMENT,
m MAP(INT, INT)
);
INSERT INTO t1 (m) VALUES ('{1:1,2:2,3:3}');
INSERT INTO t1 (m) VALUES ('{"1":1, 2 : 2 , "3 " : 3}');
INSERT INTO t1 (m) VALUES ('{1.5:2, 1.6:"3"}');
SELECT m, map_keys(m) FROM t1;
+---------------+-------------+
| m | map_keys(m) |
+---------------+-------------+
| {1:1,2:2,3:3} | [1,2,3] |
| {1:1,2:2,3:3} | [1,2,3] |
| {2:3} | [2] |
+---------------+-------------+
3 rows in set (0.002 sec)
map_values
The map_values() function returns a list of values in the target mapping. Syntax:
map_values(map)
The input parameter must be a mapped data object.
The return value is of the array type.
Example:
SELECT map_values(map(1,"apple",2,"banana"));
+-------------------------------------+
| map_values(map(1,"apple",2,"banana")) |
+-------------------------------------+
| ["apple","banana"] |
+-------------------------------------+
1 row in set (0.001 sec)
-- see the CREATE TABLE and INSERT statements in the map_keys example
SELECT m, map_values(m) FROM t1;
+---------------+---------------+
| m | map_values(m) |
+---------------+---------------+
| {1:1,2:2,3:3} | [1,2,3] |
| {1:1,2:2,3:3} | [1,2,3] |
| {2:3} | [3] |
+---------------+---------------+
3 rows in set (0.002 sec)