<comparison> operator combined with an ANY or ALL quantifier.
ANYreturnsTRUEif the comparison is true for at least one element in the array.ALLreturnsTRUEif the comparison is true for every element in the array.
Syntax
Parameters
| Parameter | Description | Supported input types |
|---|---|---|
<value> | A scalar value to compare against each element of the array. | Any comparable type |
<comparison> | A comparison operator: =, <>, !=, <, >, <=, or >=. | See Comparison operators |
<array> | The array whose elements are compared against <value>. | ARRAY with elements of a comparable type |
<value> and the element type of <array> must be comparable.
Return type
BOOLEAN
NULL handling
- If
<array>isNULL, the result isNULL. - If
<array>is empty,ANYreturnsFALSEandALLreturnsTRUE. - For
ANY: returnsTRUEas soon as a matching element is found, even if other elements areNULL. If no element matches and at least one element isNULL, the result isNULL. - For
ALL: returnsFALSEas soon as a non-matching element is found, even if other elements areNULL. If every non-NULL element matches and at least one element isNULL, the result isNULL.
Examples
Check whether a value exists in an array
true
Check whether a value equals every element
true
false
Use inequality operators
true β 5 differs from every element.
true β 1 differs from at least one element.
Use range comparisons
true β 100 is greater than every element.
true β 2 is less than at least one element.
Empty arrays
false β no elements to match against.
true β the condition holds vacuously for an empty array.
NULL values in the array
true β a match is found before the NULL matters.
NULL β no match is found, but a NULL element prevents a definitive false.
Use with table columns
The following example checks each rowβsquantity against its own valid_quantities array.
| product_id | is_valid |
|---|---|
| 1 | true |
| 2 | false |
| 3 | true |