Function Reference

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');
reverse
reward

Palindrome check

PostgreSQL 17.5
SELECT word,
	word = REVERSE(word) AS is_palindrome
FROM (
		VALUES ('level'),
			('sql')
	) AS t(word);
wordis_palindrome
leveltrue
sqlfalse

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.

See also