Skip to content
Related Articles

Related Articles

Improve Article

PostgreSQL – RIGHT Function

  • Last Updated : 01 Feb, 2021

The PostgreSQL RIGHT() function is used to query for the last n characters in a string.

Syntax: RIGHT(string, n)

Let’s analyze the above syntax:

  • The string argument is a string from which a number of the rightmost characters is to be returned.
  • The n argument specifies the number of the rightmost characters that is to be returned.

Example 1:

The following statement can be used to query for the last character in the string ‘XYZ’:

SELECT RIGHT('XYZ', 1);

Output:



Example 2:

The following query uses the RIGHT() function in WHERE clause to get all customers whose last names ended with ‘son’ in the customer table of the sample database:

SELECT last_name
FROM customer
WHERE RIGHT(last_name, 3) = 'son';

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :