PostgreSQL 18 reference · Array Functions

PostgreSQL ARRAY_APPEND() Function

Add an element to the end of an array. array_prepend() adds to the start, and || joins arrays or elements.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array_append(array, element)  |  array || element

Parameters

ParameterDescription
array An array value.
element The value to add.

Return value

A new array.

Examples

Add elements
SELECT array_append(ARRAY[1, 2], 3) AS appended, array_prepend(0, ARRAY[1, 2]) AS prepended;

Output

 appended | prepended
----------+-----------
 {1,2,3}  | {0,1,2}
(1 row)

Run this on your computer — see “Get Started” for setup.

The || operator
SELECT ARRAY[1, 2] || ARRAY[3, 4] AS joined, ARRAY['a'] || 'b'::text AS with_element;

Output

  joined   | with_element
-----------+--------------
 {1,2,3,4} | {a,b}
(1 row)

Run this on your computer — see “Get Started” for setup.

Was this page helpful?