ARRAY_LENGTH

All functions > ARRAY > ARRAY_LENGTH

Returns the number of elements in an array.

Signatures

Returns: The number of elements in the array

ARRAY_LENGTH(array: ARRAY<T>) → BIGINT
sql
ParameterTypeRequiredDescription
arrayARRAY<T>YesThe input array to count elements from

Notes

  • Counts all elements including duplicates and NULL values
  • Returns 0 for empty arrays
  • Also available as CARDINALITY alias
  • Useful for data validation and conditional logic

Aliases

  • CARDINALITY

Examples

FeatureQL
SELECT
    f1 := CARDINALITY(ARRAY[1, 2, 3, 4, 5]),  -- Count basic array elements
    f2 := CARDINALITY(ARRAY['A', 'B', 'C']),  -- Count string array elements
    f3 := CARDINALITY(ARRAY[1, 1, 2, 2, 3]),  -- Count includes duplicates
    f4 := CARDINALITY(ARRAY[1, NULL::BIGINT, 2, NULL::BIGINT]),  -- Count includes NULL values
    f5 := CARDINALITY(ARRAY[42]),  -- Single element array
    f6 := CARDINALITY(ARRAY[]::BIGINT[])  -- Empty array
;
Result
f1 BIGINTf2 BIGINTf3 BIGINTf4 BIGINTf5 BIGINTf6 BIGINT
535410

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19