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
Syntax
array_append(array, element) | array || element
Parameters
| Parameter | Description |
|---|---|
array |
An array value. |
element |
The value to add. |
Return value
A new array.
Examples
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.
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.
Related
ARRAY_CAT()· Concatenate two arrays of the same element type into one new array. The || operator does the same thing.ARRAY_REMOVE()· Remove every element equal to a given value from an array. array_replace() swaps them for another value.- SQL String Functions · tutorial