Mapping comparison functions and operators perform comparisons on mapping data and return a Boolean value. OceanBase Database supports the = and != operators.
=/!=
The = and != operators compare two mapping data items. Syntax:
map1 = map2;
map1 != map2;
The input parameters are described as follows:
map1must be a mapping data item.map2must be a mapping data item.
The return result is described as follows:
- For the
=operator,1indicates equality, and0indicates inequality. - For the
!=operator,0indicates equality, and1indicates inequality. - Two mappings are considered equal only when both their keys and values are equal.
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 to a comparable type when they are compared.
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
-- When the keys are equal but the values are not, 0 is returned.
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