PostgreSQL 18 reference · Array Functions
PostgreSQL ARRAY_REVERSE() Function
Return a copy of an array with its elements in reverse order. Added in PostgreSQL 18.
PostgreSQL 18 Since 18
Syntax
array_reverse(array)
Parameters
| Parameter | Description |
|---|---|
array |
An array value. |
Return value
A reversed array.
Examples
SELECT array_reverse(ARRAY[1, 2, 3]) AS reversed;
Output
reversed
----------
{3,2,1}
(1 row)Run this on your computer — see “Get Started” for setup.
SELECT array_reverse(array_sort(ARRAY[5, 9, 1])) AS largest_first;
Output
largest_first
---------------
{9,5,1}
(1 row)Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 18 | Added |
Related
ARRAY_SORT()· Return a copy of an array with its elements sorted, ascending by default. Added in PostgreSQL 18.- SQL String Functions · tutorial