array_length()

A function returning the length of an array dimension

array_length() is a system function returning the length of the requested array dimension.

array_length() was added in PostgreSQL 8.4.

Usage

array_length ( anyarray, integer ) → integer

NULL is returned if the array is zero-length, or a non-existent dimension is provided.

Change history

Examples

Basic usage example for array_length():

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

Using array_length() with a multi-dimensional array:

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

Categories

Arrays, System function

See also

array_dims(), array_ndims(), array_lower(), array_upper()