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

# PostgreSQL TRANSLATE() Function

The PostgreSQL `TRANSLATE()` function performs several single-character, one-to-one translations in one operation.

## Syntax

The following illustrates the syntax of the PostgreSQL `TRANSLATE()` function:

```sql
TRANSLATE(string, from, to)
```

## Arguments

The PostgreSQL `TRANSLATE()` function accepts three arguments:

**1) `string`**  
is a string subjected to translation.

**2) `from`**  
is a set of characters in the first argument (`string`) that should be replaced.

**3) `to`**  
is a set of characters that replaces the `from` in the string.

Notice that if `from` is longer than `to`, the `TRANSLATE()` function removes the occurrences of the extra characters in `from`.

## Return value

The PostgreSQL `TRANSLATE()` function returns a string with the characters in the one set of characters replaced by another set of characters.

## Examples

Let's see some examples of using the `TRANSLATE()` function to understand how it works.

### 1) Basic TRANSLATE() function example

See the following statement:

```sql
SELECT TRANSLATE('12345', '134', 'ax')
```

In this example:

- The character `'1'` in string `'12345'` is substituted by character `'a'`, The character `'3'` in the string `'12345'` is substituted by the character `'x'`.
- Because the string `'134'` has more characters than the string `'ax'`, the `TRANSLATE()` function removes the extra character in the string `'134'`, which is `'4'`, from the string `'12345'`.

The following illustrates the result:

```text
 translate
-----------
 a2x5
(1 row)
```

### 2) Single character replacement

The following example shows how to use the `TRANSLATE()` function to replace comma (,) with a semi-colon (;) in a comma-separated values list.

```sql
SELECT TRANSLATE('apple,orange,banana', ',', ';');
```

Here is the output:

```text
  translate
---------------------
 apple;orange;banana
(1 row)
```

### 3) Encrypting and decrypting a message

The following example shows how to use the `TRANSLATE()` function to encrypt a message:

```sql
SELECT TRANSLATE('a secret message',
                 'abcdefghijklmnopqrstuvxyz',
                 '0123456789acwrvyuiopkjhbq');
```

Here is the output:

```text
    translate
------------------
 0 o42i4p w4oo064
(1 row)
```

You can also decrypt the message `'0 o42i4p w4oo064'` using the function:

```sql
SELECT TRANSLATE('0 o42i4p w4oo064',
                     '0123456789acwrvyuiopkjhbq',
                     'abcdefghijklmnopqrstuvxyz');
```

Hence the output is:

```
    translate
------------------
 a secret message
(1 row)
```

In this tutorial, you have learned how to use the PostgreSQL `TRANSLATE()` function to substitute characters in a set with another, one-to-one, in a single operation.

---

## 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)
- [RPAD](https://neon.com/postgresql/postgresql-string-functions/postgresql-rpad)
- [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)
- [TRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-trim-function)
- [UPPER](https://neon.com/postgresql/postgresql-string-functions/postgresql-upper)
