TRANSLATE
Replaces individual characters in a string with other individual characters according to their position and returns the result.
Replaces individual characters in a string with other individual characters according to their position and returns the result.
Behavior type
ImmutableSyntax
TRANSLATE ( string_to_replace , from_string , to_string );
Arguments
string_to_replace- String to be translated.
from_string- Contains the characters that should be replaced in
string_to_replace. to_string- Any character in
string_to_replacethat matches a character infrom_stringis replaced by the corresponding character into_stringaccording to their position.
Examples
The following example shows how TRANSLATE matches and replaces individual characters:
=> SELECT TRANSLATE('hello world', 'el', 'ip');
TRANSLATE
-----------
hippo worpd
(1 row)
The following example performs a more complex character replacement operation to fix the syntax of an equation:
=> SELECT TRANSLATE('4*[3+2]/{6-3}', '[]{}', '()()');
TRANSLATE
-----------
4*(3+2)/(6-3)
(1 row)