Skip to main content
Quantified comparison operators compare a scalar value against the elements of an array using a <comparison> operator combined with an ANY or ALL quantifier.
  • ANY returns TRUE if the comparison is true for at least one element in the array.
  • ALL returns TRUE if the comparison is true for every element in the array.

Syntax

Parameters

The type of <value> and the element type of <array> must be comparable.

Return type

BOOLEAN

NULL handling

  • If <array> is NULL, the result is NULL.
  • If <array> is empty, ANY returns FALSE and ALL returns TRUE.
  • For ANY: returns TRUE as soon as a matching element is found, even if other elements are NULL. If no element matches and at least one element is NULL, the result is NULL.
  • For ALL: returns FALSE as soon as a non-matching element is found, even if other elements are NULL. If every non-NULL element matches and at least one element is NULL, the result is NULL.

Examples

Check whether a value exists in an array

Rows: 1Execution time: 10.46ms

Check whether a value equals every element

Rows: 1Execution time: 11.18ms

Rows: 1Execution time: 9.31ms

Use inequality operators

Rows: 1Execution time: 6.46ms

5 differs from every element.

Rows: 1Execution time: 8.25ms

1 differs from at least one element.

Use range comparisons

Rows: 1Execution time: 6.98ms

100 is greater than every element.

Rows: 1Execution time: 7.06ms

2 is less than at least one element.

Empty arrays

Rows: 1Execution time: 5.39ms

No elements to match against.

Rows: 1Execution time: 8.58ms

The condition holds vacuously for an empty array.

NULL values in the array

Rows: 1Execution time: 5.27ms

A match is found before the NULL matters.

Rows: 1Execution time: 1ms

No match is found, but a NULL element prevents a definitive false.

Use with table columns

The following example checks each row’s quantity against its own valid_quantities array.
Returns: