cardinality()

A function returning the number of elements in an array

cardinality() is a system function returning the total number of individual elements in an array.

cardinality() was added in PostgreSQL 8.4.

Usage

cardinality ( anyarray ) → integer

Change history

Examples

Basic execution example for cardinality():

postgres=# SELECT cardinality(ARRAY[1,2,3]);
 cardinality 
-------------
           3
(1 row)

With a multi-dimensional array:

postgres=# SELECT cardinality(ARRAY[ [1,2,3],[4,5,6] ]);
 cardinality 
-------------
           6
(1 row)

Categories

Arrays, System function

See also

array_dims(), array_ndims()