forall function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Tests whether func holds for all elements in the array.

Syntax

forall(expr, func)

Arguments

  • expr: An ARRAY expression.
  • func: A lambda function returning a BOOLEAN.

Returns

A BOOLEAN.

The lambda function uses one parameter passing an element of the array.

Examples

> SELECT forall(array(1, 2, 3), x -> x % 2 == 0);
 false
> SELECT forall(array(2, 4, 8), x -> x % 2 == 0);
 true
> SELECT forall(array(1, NULL, 3), x -> x % 2 == 0);
 false
> SELECT forall(array(2, NULL, 8), x -> x % 2 == 0);
 NULL