Array predicate functions evaluate the input array data and return a boolean value. OceanBase AI Database currently supports the following array predicate functions: array_contains(), array_contains_all(), and array_overlaps(). It also supports the ANY() operator.
array_contains
The array_contains() function determines whether a specific element is present in an array. The syntax is as follows:
array_contains(arr1, element)
The input parameters are described as follows:
- The type of
arr1must be an array. - The
elementfor the judgment can be of any type.
A return value of 1 indicates the string contains the specified substring, and a return value of 0 indicates it does not.
An example is as follows:
SELECT array_contains([1,2,3], 2);
+----------------------------+
| array_contains([1,2,3], 2) |
+----------------------------+
| 1 |
+----------------------------+
1 row in set
SELECT array_contains([1,2,3], 6);
+----------------------------+
| array_contains([1,2,3], 6) |
+----------------------------+
| 0 |
+----------------------------+
1 row in set
SELECT array_contains(["hello", "hi"], "hel");
+----------------------------------------+
| array_contains(["hello", "hi"], "hel") |
+----------------------------------------+
| 0 |
+----------------------------------------+
1 row in set
SELECT array_contains(["hello", "hi"], "hi");
+---------------------------------------+
| array_contains(["hello", "hi"], "hi") |
+---------------------------------------+
| 1 |
+---------------------------------------+
1 row in set
SELECT array_contains([[1,2],[3,4]], [3.0,4.0]);
+------------------------------------------+
| array_contains([[1,2],[3,4]], [3.0,4.0]) |
+------------------------------------------+
| 1 |
+------------------------------------------+
1 row in set
array_contains_all
The array_contains_all() function determines whether the input array contains all elements of another array. The syntax is as follows:
array_contains_all(arr1, arr2)
The input parameters are described as follows:
- The type of
arr1must be an array. - The type of
arr2must be an array.
The return value 1 indicates inclusion, and 0 indicates exclusion.
The input parameters arr1 and arr2 must have the same (or convertible) element type; otherwise, the operation will fail.
For example:
SELECT array_contains_all([1,2,3], [2]);
+----------------------------------+
| array_contains_all([1,2,3], [2]) |
+----------------------------------+
| 1 |
+----------------------------------+
1 row in set
SELECT array_contains_all([2], [1,2,3]);
+----------------------------------+
| array_contains_all([2], [1,2,3]) |
+----------------------------------+
| 0 |
+----------------------------------+
1 row in set
SELECT array_contains_all([1,2,3], null);
+-----------------------------------+
| array_contains_all([1,2,3], null) |
+-----------------------------------+
| NULL |
+-----------------------------------+
1 row in set
SELECT array_contains_all([1,2,3], [2.0]);
+------------------------------------+
| array_contains_all([1,2,3], [2.0]) |
+------------------------------------+
| 1 |
+------------------------------------+
1 row in set
SELECT array_contains_all(["hello", "hi"], ["hi"]);
+---------------------------------------------+
| array_contains_all(["hello", "hi"], ["hi"]) |
+---------------------------------------------+
| 1 |
+---------------------------------------------+
1 row in set
SELECT array_contains_all([[1,2],[3,4]], [[3.0,4.0]]);
+------------------------------------------------+
| array_contains_all([[1,2],[3,4]], [[3.0,4.0]]) |
+------------------------------------------------+
| 1 |
+------------------------------------------------+
1 row in set
SELECT array_contains_all([["hello", "world"], ["hi", "what"], ["are you?"]], [["are you?"]]);
+----------------------------------------------------------------------------------------+
| array_contains_all([["hello", "world"], ["hi", "what"], ["are you?"]], [["are you?"]]) |
+----------------------------------------------------------------------------------------+
| 1 |
+----------------------------------------------------------------------------------------+
1 row in set
array_overlaps
The array_overlaps() function determines whether two arrays have an intersection. The syntax is as follows:
array_overlaps(arr1, arr2)
The input parameters are described as follows:
- The type of
arr1must be an array. - The type of
arr2must be an array.
The return value 1 indicates an intersection exists, and 0 indicates no intersection exists.
The input parameters arr1 and arr2 must have the same (or convertible) element type; otherwise, the operation will fail.
For example:
SELECT array_overlaps([1,2,3], [2]);
+------------------------------+
| array_overlaps([1,2,3], [2]) |
+------------------------------+
| 1 |
+------------------------------+
1 row in set
SELECT array_overlaps([1,2,3], null);
+-------------------------------+
| array_overlaps([1,2,3], null) |
+-------------------------------+
| NULL |
+-------------------------------+
1 row in set
SELECT array_overlaps([1,2,3], [2.0]);
+--------------------------------+
| array_overlaps([1,2,3], [2.0]) |
+--------------------------------+
| 1 |
+--------------------------------+
1 row in set
SELECT array_overlaps([1.1,2.2,3.3], [2.2]);
+--------------------------------------+
| array_overlaps([1.1,2.2,3.3], [2.2]) |
+--------------------------------------+
| 1 |
+--------------------------------------+
1 row in set
SELECT array_overlaps(["hello", "hi"], ["hi"]);
+-----------------------------------------+
| array_overlaps(["hello", "hi"], ["hi"]) |
+-----------------------------------------+
| 1 |
+-----------------------------------------+
1 row in set
SELECT array_overlaps([[1,2],[3,4]], [[3,4]]);
+----------------------------------------+
| array_overlaps([[1,2],[3,4]], [[3,4]]) |
+----------------------------------------+
| 1 |
+----------------------------------------+
1 row in set
SELECT array_overlaps([[1,2],[3,4]], [[3.0,4.0]]);
+--------------------------------------------+
| array_overlaps([[1,2],[3,4]], [[3.0,4.0]]) |
+--------------------------------------------+
| 1 |
+--------------------------------------------+
1 row in set
SELECT array_overlaps([["hello", "world"], ["hi", "what"], ["are you?"]], [["are you?"]]);
+------------------------------------------------------------------------------------+
| array_overlaps([["hello", "world"], ["hi", "what"], ["are you?"]], [["are you?"]]) |
+------------------------------------------------------------------------------------+
| 1 |
+------------------------------------------------------------------------------------+
1 row in set
ANY
The ANY() operator and the array_contains() function have the same functionality, input parameters, and return values, but differ in syntax:
element = ANY(arr1)
An example is as follows:
SELECT 2 = ANY([1,2,3]);
SELECT 6 = ANY([1,2,3]);
SELECT "hel" = ANY(["hello", "hi"]);
SELECT "hi" = ANY(["hello", "hi"]);
SELECT [3.0,4.0] = ANY([[1,2],[3,4]]);