Reverse the column value in PostgreSQL

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:

Reverse the column value in PostgreSQL 1

 

 

Example 2: Reverse the column value in PostgreSQL:

We will be using Zipcodes table.

Reverse the column value in PostgreSQL 2

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:

Reverse the column value in PostgreSQL 3

 

 

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts