array_append()

A function for appending to an array

array_append() is a system function for appending an element to the end of an array.

array_append() was added in PostgreSQL 7.4.

Usage

array_append ( anyarray, anyelement ) → anyarray

Change history

Examples

Basic usage examples for array_append():

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

 array_append  
---------------
 {foo,bar,baz}
(1 row)

Note that the anyarray || anyelement operator is equivalent:

postgres=# SELECT ARRAY[1,2] || 3;
 ?column? 
----------
 {1,2,3}
(1 row)

It is not possible to append arbitrary data types to an array of a particular type:

ERROR:  function array_append(text[], integer) does not exist
LINE 1: SELECT array_append(ARRAY['foo','bar'], 1);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Categories

Arrays, System function

See also

array_prepend(), array_cat()