RIGHT
Returns the last n characters of a string.
PostgreSQL 17.5
RIGHT(string, n)Parameters
- stringtext
- Source string
- ninteger
- Number of characters, can be negative
Return value
The last n characters; with a negative n, all characters except the first |n|
Examples
Last seven characters
PostgreSQL 17.5
SELECT RIGHT('sql-academy', 7);All but the first four characters
PostgreSQL 17.5
SELECT RIGHT('sql-academy', -4);Details
If n is greater than the string length, the whole string is returned. In MySQL a negative n gives an empty string, while here it cuts characters off the start.