Array Intersection Check Function: hasany_clickhouse
Description
hasany_clickhouse is an alias for array_overlap, used to check whether two arrays share at least one common element. Specifically, the function behaves as follows:
- If the two arrays
array1andarray2share at least one common element, the function returnstrue. - If the two arrays have no intersection, but at least one array contains a
nullvalue and both arrays are non-empty, the function returnsnull. - In all other cases, the function returns
false.
Parameters
array1,array2: The two arrays to compare, of typearray<T>, whereTcan be any data type supported by the database.
Return Type
- Returns
booleanornull.
Examples
- Check whether two arrays intersect:
- When an array contains
null:
- Two non-empty arrays with no intersection:
- One array is empty:
- Both arrays are empty:
Notes
- When using the
hasany_clickhousefunction, ensure that the element types of the arrays are consistent, otherwise comparison may fail. - If an array contains
nullvalues, the function behavior differs — this should be noted carefully.
