Appearance
TRANSLATE
Replace individual characters in a string, given corresponding lists of "from" and "to" characters. See also REPLACE
TRANSLATE(string, from_chars, to_chars)
This example removes all of the vowels from the nickname column and replaces them with an empty string (no characters):
premdb=# SELECT nickname, TRANSLATE(nickname,'aeiou','') FROM team;
nickname | translate
------------+-----------
Gunners | Gnnrs
Villains | Vllns
Tykes | Tyks
Blues | Bls
Rovers | Rvrs
Seasiders | Ssdrs
...
This example removes all of the vowels and replaces each one with a zero. Note that for this example to work, 5 zeroes must be listed, one corresponding to each vowel.
premdb=# SELECT nickname, TRANSLATE(nickname,'aeiou','00000') FROM team;
nickname | translate
------------+------------
Gunners | G0nn0rs
Villains | V0ll00ns
Tykes | Tyk0s
Blues | Bl00s
Rovers | R0v0rs
Seasiders | S00s0d0rs
Trotters | Tr0tt0rs
Cherries | Ch0rr00s
...
Parent topic:String Functions