array_lower()

A function returning the lower bound of an requested array dimension

array_lower() is a system function returning the lower bound of the requested array dimension.

array_lower() was added in PostgreSQL 7.4.

Usage

array_lower ( anyarray, integer ) → integer

Given a particular array (e.g. ['foo','bar','baz']), array_lower() returns the position of the first (lowest) element, i.e. the lower array bound, which by default is 1:

postgres=# SELECT array_lower(ARRAY['foo', 'bar', 'baz'], 1);
 array_lower 
-------------
           1
(1 row)

The second parameter in the above example references the array dimension - as the example array only has one dimension, this must of course be 1.

It is also possible to specify a different starting point for the array lower bound, e,g.:

postgres=# SELECT array_lower('[0:2]={1,2,3}'::integer[], 1);
 array_lower 
-------------
           0
(1 row)

See the Examples section below for further examples.

Change history

Examples

Basic execution example for array_lower():

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

Using array_lower() with a multi-dimensional array:

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

NULL is returned if an invalid array dimension is provided:

postgres=# SELECT array_lower(ARRAY[1,2,3], 2) IS NULL;
 ?column? 
----------
 t
(1 row)

Categories

Arrays, System function

See also

array_upper(), array_length(), array_ndims()