# reverse

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/string/reverse)

Reverses the order of Unicode characters in a string.

## Syntax

```scopeql
reverse(<string>)
```

## Arguments

| Argument   | Type     | Description          |
| ---------- | -------- | -------------------- |
| `<string>` | `string` | String to transform. |

## Returns

Returns `string`. Returns NULL if the input is NULL.

## Examples

Reverse host names to build a sort key that puts shared domain suffixes together.

```scopeql
VALUES ('api.shop.example'), ('cdn.shop.example'), ('api.pay.example')
SELECT $0 AS host
SELECT host, reverse(host) AS suffix_key
ORDER BY suffix_key
```

```text
+------------------+------------------+
| host             | suffix_key       |
+------------------+------------------+
| api.shop.example | elpmaxe.pohs.ipa |
| cdn.shop.example | elpmaxe.pohs.ndc |
| api.pay.example  | elpmaxe.yap.ipa  |
+------------------+------------------+
```

This reverses characters; it does not parse or reverse domain components.
