Skip to content

RIGHT

Return the last n characters in a string. If n is a negative number, return all but the first n characters. (See also LEFT.)

RIGHT(string, number)

For example, return the last 3 characters in the capacity column:

premdb=# SELECT stadium, RIGHT(capacity::CHAR(5),3) 
FROM team WHERE capacity>0 ORDER BY 2;
      stadium        | right 
----------------------+-------
 The Hawthorns        | 000
 Stadium of Light     | 000
 Oakwell Stadium      | 009
 St. Andrew's         | 016
 Upton Park           | 016
 Etihad Stadium       | 097
 Fratton Park         | 100
 The Valley           | 111
...

Note that the column has to be cast to a CHAR column before the RIGHT function is applied.

Parent topic:String Functions