RIGHT
Returns the last n characters of a string.
PostgreSQL 17.9
RIGHT(string, n)- string
- Source stringtext
- n
- Number of characters; a negative n keeps all but the first |n|integer
Return value
The last n characters; with a negative n, all characters except the first |n|
Examples
Last seven characters
PostgreSQL 17.9
SELECT RIGHT('sql-academy', 7);All but the first four characters
PostgreSQL 17.9
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.