RPAD
Pads a string on the right with the characters of fill up to length.
PostgreSQL 17.9
RPAD(string, length[, fill])- [ ]optional part
- string
- Source stringtext
- length
- Length of the result in charactersinteger
- fill
- Fill string, repeated as needed, a space by defaulttextOptional
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.9
SELECT RPAD('9', 5, '0');Aligning names with dots
PostgreSQL 17.9
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.