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

# PostgreSQL REVERSE() Function

**Info:** The REVERSE() function works the same across any PostgreSQL deployment, so anything you learn here applies wherever you run Postgres. For enterprises building in the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers the best managed cloud Postgres, with high performance, strong security, and native integration into the Lakehouse. For developers and startups who need to ship features and scale on day one, [Neon](https://neon.com) is the Postgres platform built for speed.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `REVERSE()` function to reverse the characters within a string.

## Introduction to PostgreSQL REVERSE() function

The `REVERSE()` function accepts a string and returns a new string with the order of all characters reversed.

Here's the syntax of the `REVERSE()` function:

```sql
REVERSE(text)
```

In this syntax:

- `text`: The input string that you want to reverse.

The `REVERSE()` function returns a string with the order of all the characters reversed.

The `REVERSE()` function returns `NULL` if the `text` is `NULL`.

## MySQL REVERSE() function examples

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

### 1) Basic PostgreSQL REVERSE() function example

The following example uses the `REVERSE()` function to reverse the string `"SQL"`:

```sql
SELECT REVERSE('SQL');
```

Output:

```text
 reverse
---------
 LQS
(1 row)
```

### 2) Using the PostgreSQL REVERSE() function with table data

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

![customer table](https://neon.com/postgresqltutorial/customer.png)The following example uses the `REVERSE()` function to reverse the first names of customers:

```sql
SELECT
  first_name,
  REVERSE(first_name)
FROM
  customer
ORDER BY
  first_name;
```

Output:

```text
 first_name  |   reverse
-------------+-------------
 Aaron       | noraA
 Adam        | madA
 Adrian      | nairdA
 Agnes       | sengA
```

### 3) Using REVERSE() function to detect palindromes

A palindrome is a string that reads the same forward and backward such as `"radar"`.

You can use the `REVERSE()` function to reverse a string and then compare the reversed string with the original string to determine if it is a palindrome. For example:

First, [create a new table](../postgresql-tutorial/postgresql-create-table) called `words` to store the words:

```sql
CREATE TABLE words(
  id SERIAL PRIMARY KEY,
  word VARCHAR(255) NOT NULL
);
```

Second, [insert some rows](../postgresql-tutorial/postgresql-insert-multiple-rows) into the `words` table:

```sql
INSERT INTO words(word)
VALUES('radar'), ('level'),('civic'),('man'),('12321'),('madam')
RETURNING *;
```

Output:

```text
 id | word
----+-------
  1 | radar
  2 | level
  3 | civic
  4 | man
  5 | 12321
  6 | madam
(6 rows)
```

Third, determine if a value in the `word` column is a palindrome using the `REVERSE()` function:

```sql
SELECT
  word,
  REVERSE(word),
  (
    word = REVERSE(word)
  ) palindrome
FROM
  words;
```

Output:

```text
 word  | reverse | palindrome
-------+---------+------------
 radar | radar   | t
 level | level   | t
 civic | civic   | t
 man   | nam     | f
 12321 | 12321   | t
 madam | madam   | t
(6 rows)
```

## Summary

- Use the PostgreSQL `REVERSE()` function to reverse the order of characters within a string.

---

## 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)
- [REPEAT](https://neon.com/postgresql/string-functions/repeat)
- [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)
