postgresql - replace all instances of a string within text field

The Solution to postgresql - replace all instances of a string within text field is


You want to use postgresql's replace function:

replace(string text, from text, to text)

for instance :

UPDATE <table> SET <field> = replace(<field>, 'cat', 'dog')

Be aware, though, that this will be a string-to-string replacement, so 'category' will become 'dogegory'. the regexp_replace function may help you define a stricter match pattern for what you want to replace.

~ Answered on 2011-02-20 22:35:23


Most Viewed Questions: