Map comparison functions and operators are used to evaluate input map data and return a boolean value. The operators currently supported by the OceanBase database include = and !=.
= and !=
The = and != operators are used to compare two map data types for equality. The syntax is as follows:
map1 = map2;
map1 != map2;
Description of the input parameters:
map1: The input must be of a map data type.map2: The input must also be of a map data type.
Explanation of the return results:
- For
=,1indicates equality, while0indicates inequality. - For
!=,0indicates equality, while1indicates inequality. - A map is considered equal only when both its keys and values are identical.
Here are some examples:
SELECT map(1,"a",2,"b") = map(1,"a",2,"b");
+-------------------------------------+
| map(1,"a",2,"b") = map(1,"a",2,"b") |
+-------------------------------------+
| 1 |
+-------------------------------------+
1 row in set
-- The system automatically converts arrays into comparable types during comparison.
SELECT map(1,"a",2,"b") = map("1","a","2","b");
+-----------------------------------------+
| map(1,"a",2,"b") = map("1","a","2","b") |
+-----------------------------------------+
| 1 |
+-----------------------------------------+
1 row in set
-- The return value is 0 because the keys are equal but the values are not.
SELECT map(1,"a",2,"b") = map(1,"a",2,"c");
+-------------------------------------+
| map(1,"a",2,"b") = map(1,"a",2,"c") |
+-------------------------------------+
| 0 |
+-------------------------------------+
1 row in set