PostgreSQL – RIGHT Function

The RIGHT function in postgreSQL is used to extract a specified number of characters from the end (right side) of a string. The syntax of the RIGHT function is as shown below:

RIGHT(string, length)

where string is the input string from which you want to extract characters,

and length is the number of characters you want to extract from the right side of the input string.

Here’s an example of how you might use the RIGHT function in a SQL query:

SELECT RIGHT('Hello, World!', 6);

In this example, the result would be the string 'World!', because the RIGHT function extracted the last 6 characters from the input string.

If the specified length is greater than the length of the input string, the RIGHT function will simply return the entire input string.

SELECT RIGHT('Hi', 5);

In this case, the result would still be the string 'Hi', because the length of the input string is less than the specified length.

Similar Posts