REVERSE
Reverses a string: the last character becomes the first.
PostgreSQL 17.5
REVERSE(string)Parameters
- stringtext
- Source string
Return value
A string (text) with the characters in reverse order
Examples
String reversed
PostgreSQL 17.5
SELECT REVERSE('drawer');Palindrome check
PostgreSQL 17.5
SELECT word,
word = REVERSE(word) AS is_palindrome
FROM (
VALUES ('level'),
('sql')
) AS t(word);Details
REVERSE helps find the last occurrence of a character: LENGTH(s) - STRPOS(REVERSE(s), ' ') + 1 is the position of the last space in the string s.