Skip to content

REPLACE

Replace all occurrences of an exact sequence of characters in a string with another exact sequence of characters. (Characters are not replaced individually.) See also TRANSLATE.

REPLACE(string, FROM characters, TO characters)

The following examples show the different behavior of the REPLACE and TRANSLATE functions.

premdb=# SELECT nickname, REPLACE(nickname, 'ue','00000') 
FROM team WHERE teamid BETWEEN 1 AND 5;
 nickname | replace  
----------+----------
 Gunners  | Gunners
 Villains | Villains
 Tykes    | Tykes
 Blues    | Bl00000s
 Rovers   | Rovers
(5 rows)

premdb=# SELECT nickname, TRANSLATE(nickname, 'ue','00000') 
FROM team WHERE teamid between 1 and 5;
 nickname | translate 
----------+-----------
 Gunners  | G0nn0rs
 Villains | Villains
 Tykes    | Tyk0s
 Blues    | Bl00s
 Rovers   | Rov0rs
(5 rows)

Parent topic:String Functions