v.22.7New Feature

Add translate and translateUTF8 functions for character translation

Add functions translate(string, from_string, to_string) and translateUTF8(string, from_string, to_string). It translates some characters to another. #38935 (Nikolay Degterinsky).
Added two new functions, translate(string, from_string, to_string) and translateUTF8(string, from_string, to_string), which replace characters in a string by translating each character from from_string to the corresponding character in to_string.

Why it matters

These functions provide an efficient way to perform character-by-character translation or replacement within strings. This is useful for tasks such as character normalization, encoding adjustments, or simple substitutions without the need for complex regex operations.

How to use it

Use the functions by specifying the input string, the from_string containing characters to be replaced, and the to_string containing their replacements. For example:

SELECT translate('hello', 'leo', '123');
-- Result: h2133


Use translateUTF8 when working with UTF-8 encoded strings that include multibyte characters.