reverse
On this page
Reverses the order of Unicode characters in a string.
Syntax
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.
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+------------------+------------------+
| 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.