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

# PostgreSQL REPEAT() Function

**Info:** The REPEAT() function works the same way across any PostgreSQL deployment, so what you learn here carries over wherever you run Postgres. If you're an enterprise looking for managed Postgres in the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers the performance, security, and native Lakehouse integration your teams need. If you're a developer or startup who needs to ship and scale quickly, [Neon](https://neon.com) gives you the fastest path from idea to production on Postgres.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `REPEAT()` function to repeat a string a specified number of times.

## Introduction to PostgreSQL REPEAT() function

In PostgreSQL, the `REPEAT()` function repeats a string a specified number of times.

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

```sql
REPEAT(string, number)
```

In this syntax:

- `string`. The string that you want to repeat.
- `number`. The number of times that you want to repeat the `string` in the resulting string.

The `REPEAT()` function returns a string that repeats `number` times. If the `number` is less than 1, the function returns an empty string.

If `string` or `number` is `NULL`, the `REPEAT()` function returns `NULL`.

The `REPEAT()` function can be particularly useful when you want to format the data for display.

## PostgreSQL REPEAT() function examples

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

### 1) Basic REPEAT() function example

The following example uses the `REPEAT()` function to repeat the letter "A" there times:

```sql
SELECT REPEAT('A',3);
```

Output:

```text
 repeat
--------
 AAA
(1 row)
```

In this example, the `REPEAT()` function returns a string `"AAA"` that repeats the letter `"A"` three times.

### 2) Using the REPEAT() function to draw a bar chart

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

![PostgreSQL REPEAT() Function - Sample Table](https://www.mysqltutorial.org//postgresqltutorial/products.svg)
The following example uses the `REPEAT()` function to create a bar chart illustrating the counts of films based on their ratings:

```sql
SELECT
  rating,
  count(film_id),
  REPEAT(
    '*',
    (
      COUNT(film_id) / 10
    ) :: INT
  ) chart
FROM
  film
GROUP BY
  rating;
```

Output:

```text
 rating | count |         chart
--------+-------+------------------------
 PG-13  |   223 | **********************
 NC-17  |   210 | *********************
 R      |   195 | *******************
 G      |   178 | *****************
 PG     |   194 | *******************
(5 rows)
```

## Summary

- Use the `REPEAT()` function to repeat a string a specified number of times.

---

## Related docs (String Functions)

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