PostgreSQL 18 reference · String Functions
PostgreSQL REVERSE() Function
Return a string with its characters in reverse order. Since PostgreSQL 18 it also reverses bytea values.
PostgreSQL 18 Since 9.1
Syntax
reverse(string)
Parameters
| Parameter | Description |
|---|---|
string |
The input text. |
Return value
Text.
Examples
SELECT reverse('camel') AS a, reverse('añejo') AS multibyte_safe;
Output
a | multibyte_safe -------+---------------- lemac | ojeña (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT word, word = reverse(word) AS palindrome
FROM (VALUES ('racecar'), ('camel')) AS t(word);
Output
word | palindrome ---------+------------ racecar | t camel | f (2 rows)
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 9.1 | Added |
| PostgreSQL 18 | Also accepts bytea, reversing the bytes. |
Related
REPEAT()· Repeat a string a given number of times. A count of 0 or less gives an empty string.- SQL String Functions · tutorial