And*_*rew 4 sql postgresql replace
我有一个大约有10k记录的数据库,其中一些包含我想要替换的HTML字符.
例如,我可以找到所有出现的事件:
SELECT * FROM TABLE
WHERE TEXTFIELD LIKE '%/%'
Run Code Online (Sandbox Code Playgroud)
原始字符串示例:
this is the cool mega string that contains /
如何更换所有/有/?
最终结果应该是:
this is the cool mega string that contains /
dav*_*tty 16
如果要将特定字符串替换为另一个字符串或转换该字符串,可以在postgresql中使用"替换"函数.例如,要在"myfield"列中用"dog"替换所有出现的"cat",你会这样做:
UPDATE tablename
SET myfield = replace(myfield,"cat", "dog")
Run Code Online (Sandbox Code Playgroud)
您可以根据需要添加WHERE子句或任何其他逻辑.
或者,如果您尝试转换HTML实体,ASCII字符或各种编码方案之间,postgre也具有此功能. Postgresql字符串函数.