Counts the number of elements in the specified array for which
function(array[i]) evaluates to TRUE, if a function is provided. If
<function> is not provided, counts the number of elements in the array that evaluate to TRUE. To count the elements in an array without any conditions, use the LENGTH function instead.
|Parameter||Description||Supported input types|
| ||Optional. A Lambda function used to check elements in the array. If ||Any Lambda function|
| ||An array of elements|| |
The example below searches through the array for any elements that are greater than 3. Only one number that matches this criteria is found, so the function returns
SELECT ARRAY_COUNT(x -> x > 3, [ 1, 2, 3, 9 ]) AS levels;
In this example below, there is no
<function> criteria provided in the
ARRAY_COUNT function. This means the function will count all of the non-false elements in the array.
0 is not counted because it evaluates to
SELECT ARRAY_COUNT([TRUE, '0', 1::BOOLEAN, 3 is not null, null is null]) AS levels;