From 52fc14eb029d55af5134423b5a41cc4e31d84a60 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Fri, 6 Dec 2024 13:19:55 +0000 Subject: [PATCH] Docs: Follow-up to #71441 --- .../functions/string-replace-functions.md | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/en/sql-reference/functions/string-replace-functions.md b/docs/en/sql-reference/functions/string-replace-functions.md index f8d46cacbdc..58bdab224fd 100644 --- a/docs/en/sql-reference/functions/string-replace-functions.md +++ b/docs/en/sql-reference/functions/string-replace-functions.md @@ -253,7 +253,11 @@ SELECT format('{} {}', 'Hello', 'World') ## translate -Replaces characters in the string `s` using a one-to-one character mapping defined by `from` and `to` strings. `from` and `to` must be constant ASCII strings. Non-ASCII characters in the original string are not modified. If the number of characters in `from` list is larger than the `to` list, non overlapping characters will be deleted from the input string. +Replaces characters in the string `s` using a one-to-one character mapping defined by `from` and `to` strings. +`from` and `to` must be constant ASCII strings. +If `from` and `to` have equal sizes, each occurrence of the 1st character of `first` in `s` is replaced by the 1st character of `to`, the 2nd character of `first` in `s` is replaced by the 2nd character of `to`, etc. +If `from` contains more characters than `to`, all occurrences of the characters at the end of `from` that have no corresponding character in `to` are deleted from `s`. +Non-ASCII characters in `s` are not modified by the function. **Syntax** @@ -275,6 +279,20 @@ Result: └───────────────┘ ``` +`from` and `to` arguments have different lengths: + +``` sql +SELECT translate('clickhouse', 'clickhouse', 'CLICK') AS res +``` + +Result: + +``` text +┌─res───┐ +│ CLICK │ +└───────┘ +``` + ## translateUTF8 Like [translate](#translate) but assumes `s`, `from` and `to` are UTF-8 encoded strings.