PostgreSQL - RIGHT Function Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The PostgreSQL RIGHT() function, allows you to extract a specified number of characters from the right side of a string. This function can be incredibly useful for various text-processing tasks.Let us get a better understanding of the RIGHT Function in PostgreSQL from this article.SyntaxRIGHT(string, n)ParametersLet's analyze the above syntax:string: The input string from which you want to extract the rightmost characters.n: An integer specifying the number of characters to be extracted from the right end of the string.PostgreSQL RIGHT Function ExamplesLet us take a look at some of the examples of the RIGHT Function in PostgreSQL to better understand the concept.Example 1: Retrieving the Last Character of a StringThe following statement can be used to query for the last character in the string 'XYZ'.Query:SELECT RIGHT('XYZ', 1);Output:Explanation: In this example, the RIGHT() function takes the string 'XYZ' and the integer 1 as arguments. It returns the last character of the string, which is 'Z'.Example 2: Using RIGHT() to Filter Data in a WHERE ClauseThe 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.Query:SELECT last_name FROM customer WHERE RIGHT(last_name, 3) = 'son';Output:Explanation: In this query, the RIGHT() function is used within the WHERE clause to filter the customer table. It extracts the last three characters of each 'last_name' and compares them to 'son'. The query returns all rows where the last three characters of the 'last_name' match 'son'. Important Points About PostgreSQL RIGHT FunctionThe RIGHT() function does not support negative values for the 'n' parameter. The RIGHT() function works not only with text and character strings but also with other data types that can be implicitly cast to text, such as 'varchar' and 'char'.If the 'n' value is greater than the length of the string, RIGHT() will return the entire string without raising an error.Trailing spaces in strings are preserved when using RIGHT(). If you need to remove trailing spaces, combine RIGHT() with the TRIM() function. Comment More info R rajukumar19 Follow Improve Article Tags : PostgreSQL PostgreSQL-function PostgreSQL-String-function Explore BasicsPostgreSQL Tutorial8 min readWhat is PostgreSQL - Introduction2 min readInstall PostgreSQL on Windows2 min readInstall PostgreSQL on Mac3 min readDatabase OperationsPostgreSQL - Create Database5 min readPostgreSQL - Loading a Database3 min readPostgreSQL ALTER DATABASE3 min readPostgreSQL - Rename Database4 min readPostgreSQL - Show Databases3 min readData TypesPostgreSQL - Data Types5 min readPostgreSQL - Boolean Data Type4 min readPostgreSQL - CHAR Data Type5 min readPostgreSQL - VARCHAR Data Type3 min readPostgreSQL - NUMERIC Data Type5 min readPostgreSQL - Date Data Type4 min readPostgreSQL - TIME Data Type4 min readPostgreSQL - JSON Data Type4 min readPostgreSQL - CREATE DOMAIN3 min readQuerying TablesPostgreSQL - SELECT3 min readPostgreSQL - ORDER BY clause2 min readPostgreSQL - WHERE clause6 min readPostgreSQL FETCH Clause4 min readPostgreSQL - IN operator4 min readPostgreSQL - HAVING clause4 min readPostgreSQL - GROUP BY clause4 min readPostgreSQL - LIKE operator5 min readPostgreSQL - BETWEEN Operator3 min readTable OperationsPostgreSQL - CREATE TABLE5 min readPostgreSQL - SELECT INTO4 min readPostgreSQL - CREATE SEQUENCE4 min readPostgreSQL - ALTER TABLE6 min readPostgreSQL - ADD COLUMN4 min readPostgreSQL - DROP COLUMN2 min readPostgreSQL - Rename Table2 min readPostgreSQL - DROP TABLE5 min readPostgreSQL - TRUNCATE TABLE4 min readPostgreSQL - Copy a Table3 min readPostgreSQL - Comparing Tables3 min readPostgreSQL - Show Tables4 min readModifying DataPostgreSQL - INSERT4 min readPostgreSQL - Insert Multiple Values in Various Rows3 min readPostgreSQL UPDATE Statement5 min readPostgreSQL - DELETE4 min readPostgreSQL - Upsert4 min readConditionalsPostgreSQL - CASE3 min readPostgreSQL COALESCE5 min readPostgreSQL - NULLIF() Function4 min readPostgreSQL - CAST3 min readControl FlowPostgreSQL - IF Statement5 min readPostgreSQL - CASE Statement4 min readPostgreSQL - Loop Statement3 min readPostgreSQL - While Loops4 min readPostgreSQL - Exit Statement3 min readPostgreSQL - Continue3 min readTransactions & ConstraintsPostgreSQL - Transactions4 min readPostgreSQL - COMMIT4 min readPostgreSQL - Primary Key4 min readPostgreSQL - Foreign Key5 min readPostgreSQL - CHECK Constraint2 min readPostgreSQL - UNIQUE Constraint3 min readPostgreSQL - NOT NULL Constraint3 min readJOINS & SchemasPostgreSQL - Joins5 min readPostgreSQL - LEFT JOIN5 min readPostgreSQL - INNER JOIN2 min readPostgreSQL - FULL OUTER JOIN4 min readPostgreSQL - SELF JOIN4 min readPostgreSQL - Schema5 min readPostgreSQL - CREATE SCHEMA5 min readPostgreSQL - DROP SCHEMA4 min readPostgreSQL - ALTER SCHEMA3 min read Like