SetIntersect (NoSQL query)
APPLIES TO: NoSQL
Compares expressions in two sets and returns the set of expressions that is contained in both sets with no duplicates.
Syntax
SetIntersect(<array_expr_1>, <array_expr_2>)
Arguments
Description | |
---|---|
array_expr_1 |
An array of expressions. |
array_expr_2 |
An array of expressions. |
Return types
Returns an array of expressions.
Examples
This first example uses the function with static arrays to demonstrate the intersect functionality.
SELECT VALUE {
simpleIntersect: SetIntersect([1, 2, 3, 4], [3, 4, 5, 6]),
emptyIntersect: SetIntersect([1, 2, 3, 4], []),
duplicatesIntersect: SetIntersect([1, 2, 3, 4], [1, 1, 1, 1]),
noMatchesIntersect: SetIntersect([1, 2, 3, 4], ["A", "B"]),
unorderedIntersect: SetIntersect([1, 2, "A", "B"], ["A", 1])
}
[
{
"simpleIntersect": [
3,
4
],
"emptyIntersect": [],
"duplicatesIntersect": [
1
],
"noMatchesIntersect": [],
"unorderedIntersect": [
"A",
1
]
}
]
This last example uses a single item that share values within two array properties.
[
{
"name": "Snowilla vest",
"inStockColors": [
"Rhino",
"Finch"
],
"colors": [
"Finch",
"Mine Shaft",
"Rhino"
],
"category": "modern-vests"
}
]
The query selects the appropriate field from the item[s] in the container.
SELECT
p.name,
SetIntersect(p.colors, p.inStockColors) AS availableColors
FROM
products p
WHERE
p.category = "modern-vests"
[
{
"name": "Snowilla vest",
"availableColors": [
"Rhino",
"Finch"
]
}
]
Remarks
- This function doesn't return duplicates.
- This function doesn't use the index.