In PostgreSQL, to reverse the value of a column we will be using the reverse() function. This function takes a string and returns the string with its characters in reverse order. Let’s see how to
- Reverse the column value in PostgreSQL.
Syntax of REVERSE() function in PostgreSQL:
REVERSE(string)
- string: The string or column to be reversed.
Examples
Example 1: Reversing a Specific String
To reverse the string ‘PostgreSQL’:
SELECT REVERSE('PostgreSQL') AS reversed_string;
The reversed string value will be
Output:
Example 2: Reverse the column value in PostgreSQL:
We will be using Zipcodes table.
In order to reverse the column value in PostgreSQL we use REVERSE() function.
select *,REVERSE(city) as Reverse_city FROM zipcodes
Reverse function of city column reverse the column so the resultant table will be
Output: