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

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

Syntax

array_reverse(array)

Parameters

ParameterDescription
array An array value.

Return value

A reversed array.

Examples

Reverse
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.

Sort descending another way
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

VersionChange
PostgreSQL 18Added

Was this page helpful?