w3resource

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.

Uses of RIGHT() Function
  • Extracting Substrings: Retrieve specific portions of a string from the right.

  • String Manipulation: Modify text data by extracting characters from the end.

  • Data Formatting: Format strings by extracting relevant suffixes.

  • Conditional Extraction: Handle both positive and negative values for flexible substring extraction.

  • Text Processing: Useful in scenarios where specific portions of string data are needed.

Syntax:

right(<string>,n)

PostgreSQL Version: 9.3

Pictorial Presentation of PostgreSQL RIGHT() function

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.

Code:

SELECT right('w3resource',5);

Sample 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.

Code:

SELECT right('w3resource',-3);

Sample Output:

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

Previous: TRANSLATE function
Next: REVERSE function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/PostgreSQL/right-function.php