sql - Replace all occurrences of a substring in a database text field -
i have database has around 10k records , of them contain html characters replace.
for example can find occurrences:
select * table textfield '%/%'
the original string example:
this cool mega string contains /
how replace /
/
?
the end result should be:
this cool mega string contains /
if want replace specific string string or transformation of string, use "replace" function in postgresql. instance, replace occurances of "cat" "dog" in column "myfield", do:
update tablename set myfield = replace(myfield,"cat", "dog")
you add clause or other logic see fit.
alternatively, if trying convert html entities, ascii characters, or between various encoding schemes, postgre has functions well. postgresql string functions.
Comments
Post a Comment