RPAD
Pads a string on the right with the characters of fill up to length.
PostgreSQL 17.5
RPAD(string, length[, fill])Parameters
- stringtext
- Source string
- lengthinteger
- Length of the result in characters
- filltextoptional
- Fill string, repeated as needed, a space by default
Return value
A string of exactly length characters: a longer string is cut off on the right; with an empty fill the string is not padded
Examples
Padding with zeros on the right
PostgreSQL 17.5
SELECT RPAD('9', 5, '0');Aligning names with dots
PostgreSQL 17.5
SELECT RPAD(good_name, 15, '.') AS name
FROM Goods;Details
The first argument must be a string: cast a number to text first, for example RPAD(member_id::text, 3, '0'), while RPAD(5, 3, '0') causes an error.