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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

rpad(string, length, fill)

Parameters

ParameterDescription
string The input text.
length The final length in characters.
fill optional Padding text. Default: ' '

Return value

Text.

Examples

Dot leaders
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.

Fixed-width columns
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.

Was this page helpful?