PostgreSQL 18 reference · String Functions
PostgreSQL RPAD() Function
Pad a string on the right to a given length with spaces or another string. Longer strings are cut to that length.
PostgreSQL 18
Syntax
rpad(string, length, fill)
Parameters
| Parameter | Description |
|---|---|
string |
The input text. |
length |
The final length in characters. |
fill optional |
Padding text. Default: ' ' |
Return value
Text.
Examples
SELECT rpad('Tea', 8, '.') || '3.50' AS menu_line;
Output
menu_line -------------- Tea.....3.50 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT rpad(name, 12) || '|' AS aligned
FROM categories;
Output
aligned --------------- Books | Electronics | Home | Toys | (4 rows)
Run this on your computer — see “Get Started” for setup.
Related
LPAD()· Pad a string on the left to a given length with spaces or another string. Longer strings are cut to that length.REPEAT()· Repeat a string a given number of times. A count of 0 or less gives an empty string.- SQL String Functions · tutorial