array_cat()

A function for concatenating arrays

array_cat() is a  system function for concatenating two arrays.

array_cat() was added in PostgreSQL 7.4.

Usage

array_cat ( anyarray, anyarray ) → anyarray

Change history

Examples

Basic usage examples for array_cat():

postgres=# SELECT array_cat(array[1,2], array[3,4]);
 array_cat 
-----------
 {1,2,3,4}
(1 row)

postgres=# SELECT array_cat(array['foo','bar'], array['baz','boo']);
     array_cat     
-------------------
 {foo,bar,baz,boo}
(1 row)

Note that the anyarray || anyarray operator is equivalent:

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

It is not possible to concatenate arrays of different data types:

postgres=# SELECT array_cat(array['foo','bar'], array[3, 4]);
ERROR:  function array_cat(text[], integer[]) does not exist
LINE 1: SELECT array_cat(array['foo','bar'], array[3, 4]);
               ^
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_append(), array_prepend()