v.22.7New Feature
Add translate and translateUTF8 functions for character translation
Add functionstranslate(string, from_string, to_string)andtranslateUTF8(string, from_string, to_string). It translates some characters to another. #38935 (Nikolay Degterinsky).
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 inputstring, the from_string containing characters to be replaced, and the to_string containing their replacements. For example:SELECT translate('hello', 'leo', '123');
-- Result: h2133Use
translateUTF8 when working with UTF-8 encoded strings that include multibyte characters.