> This page location: String Functions > RPAD
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL RPAD() Function

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `RPAD()` function to extend a string to a length by filing characters.

## Introduction to the PostgreSQL RPAD() function

The `RPAD()` function allows you to extend a string to a length by appending specified characters.

Here's the basic syntax of the `RPAD()` function:

```sql
RPAD(string, length, fill)
```

In this syntax:

- `string`: The input string that you want to extend.
- `length`: The desired length of the string after padding.
- `fill`: The character or string used for padding.

The `RPAD()` function returns the string, right-padded with the string `fill` to a length of `length` characters.

If the length of the `string` is greater than the desired `length`, the `RPAD()` function truncates the `string` to the `length` characters.

If any argument `string`, `length`, or `fill` is `NULL`, the `RPAD()` function returns [`NULL`](https://www.mysqltutorial.org/mysql-basics/mysql-null/).

The `RPAD()` function can be particularly useful when you need to format text with a consistent length, align text in columns, or prepare data for display.

To left-pad a string to a length with specified characters, you can use the [`LPAD()`](https://neon.com/postgresql/postgresql-string-functions/postgresql-lpad) function.

## PostgreSQL RPAD() function examples

Let's explore some examples of using the PostgreSQL `RPAD()` function.

### 1) Basic PostgreSQL RPAD() function

The following example uses the `RPAD()` function to extend a string by filling zeros ('0') to make it six characters long:

```sql
SELECT RPAD('123', 6, '0');
```

Output:

```text
  rpad
--------
 123000
(1 row)
```

### 2) Using the RPAD() function with the table data example

We'll use the `film` table from the [sample database](../postgresql-getting-started/postgresql-sample-database):

![](https://neon.com/postgresqltutorial/film.png)The following example uses the `RPAD()` function to right-pad the titles from the `film` table with the character '.' to make it 50 characters long:

```sql
SELECT
  RPAD(title, 50, '.')
FROM
  film;
```

Output:

```text
                        rpad
----------------------------------------------------
 Chamber Italian...................................
 Grosse Wonderful..................................
 Airport Pollock...................................
 Bright Encounters.................................
 Academy Dinosaur..................................
...
```

### 3) Using the RPAD() function to truncate strings

The following example uses the `RPAD()` function to truncate the titles if their lengths are more than 10 characters:

```sql
SELECT
  title, RPAD(title, 10, '') result
FROM
  film;
```

Output:

```
            title            |   result
-----------------------------+------------
 Chamber Italian             | Chamber It
 Grosse Wonderful            | Grosse Won
 Airport Pollock             | Airport Po
 Bright Encounters           | Bright Enc
 Academy Dinosaur            | Academy Di
 Ace Goldfinger              | Ace Goldfi
...
```

## Summary

- Use PostgreSQL `RPAD()` function to extend a string to a length by appending specified characters.

---

## Related docs (String Functions)

- [ASCII](https://neon.com/postgresql/postgresql-string-functions/postgresql-ascii)
- [CHR](https://neon.com/postgresql/postgresql-string-functions/postgresql-chr)
- [CONCAT](https://neon.com/postgresql/postgresql-string-functions/postgresql-concat-function)
- [CONCAT_WS](https://neon.com/postgresql/postgresql-string-functions/postgresql-concat_ws)
- [FORMAT](https://neon.com/postgresql/postgresql-string-functions/postgresql-format)
- [INITCAP](https://neon.com/postgresql/postgresql-string-functions/postgresql-initcap)
- [LEFT](https://neon.com/postgresql/postgresql-string-functions/postgresql-left)
- [LENGTH](https://neon.com/postgresql/postgresql-string-functions/postgresql-length-function)
- [LOWER](https://neon.com/postgresql/postgresql-string-functions/postgresql-lower)
- [LPAD](https://neon.com/postgresql/postgresql-string-functions/postgresql-lpad)
- [LTRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-ltrim)
- [MD5](https://neon.com/postgresql/postgresql-string-functions/postgresql-md5)
- [POSITION](https://neon.com/postgresql/postgresql-string-functions/postgresql-position)
- [REGEXP_MATCHES](https://neon.com/postgresql/postgresql-string-functions/postgresql-regexp_matches)
- [REGEXP_REPLACE](https://neon.com/postgresql/postgresql-string-functions/regexp_replace)
- [REPEAT](https://neon.com/postgresql/postgresql-string-functions/postgresql-repeat)
- [REVERSE](https://neon.com/postgresql/postgresql-string-functions/postgresql-reverse)
- [REPLACE](https://neon.com/postgresql/postgresql-string-functions/postgresql-replace)
- [RIGHT](https://neon.com/postgresql/postgresql-string-functions/postgresql-right)
- [RTRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-rtrim)
- [SPLIT_PART](https://neon.com/postgresql/postgresql-string-functions/postgresql-split_part)
- [SUBSTRING](https://neon.com/postgresql/postgresql-string-functions/postgresql-substring)
- [TO_CHAR](https://neon.com/postgresql/postgresql-string-functions/postgresql-to_char)
- [TO_NUMBER](https://neon.com/postgresql/postgresql-string-functions/postgresql-to_number)
- [TRANSLATE](https://neon.com/postgresql/postgresql-string-functions/postgresql-translate)
- [TRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-trim-function)
- [UPPER](https://neon.com/postgresql/postgresql-string-functions/postgresql-upper)
