PostgreSQL RIGHT Function

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PostgreSQL RIGHT() function

RIGHT() function

The PostgreSQL right() function is used to extract n number of characters specified in the argument from the right of a given string. When the value of n is negative, the extraction will happen from the right except for first n characters.

Syntax :

right(<string>,n)

PostgreSQL Version : 9.3

Pictorial Presentation of PostgreSQL RIGHT() function

 

Example 1 : PostgreSQL RIGHT() function :

In the example below, the rightmost five characters from the string 'w3resource' have been extracted.

SELECT right('w3resource',5);

Output :

 right
-------
 ource
(1 row)

Example 2 :

In the example below, the right function extracted all the characters from the right side except 3 leftmost characters from the string 'w3resource', because the value of extracting character number is negative.

SELECT right('w3resource',-3);

Output :

  right
---------
 esource
(1 row)