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
| Parameter | Type | Required | Description |
|---|---|---|---|
array | ARRAY<T> | Yes | The 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 BIGINT | f2 BIGINT | f3 BIGINT | f4 BIGINT | f5 BIGINT | f6 BIGINT |
|---|---|---|---|---|---|
| 5 | 3 | 5 | 4 | 1 | 0 |
On this page