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

Immutable

Syntax

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_replace that matches a character in from_string is replaced by the corresponding character in to_string according 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)