Postgres替换字符串中的字符

18

我有一个包含文本的列,需要更改其中的字符!例如:

  • �ay---->需要改为 Day
  • �rag---->需要改为 Drag

所以我需要用字符 D 替换 �。 我尝试了以下代码,但是出现了错误:无效的正则表达式:量词操作数无效。

update  tableT pp set descript=(select regexp_replace(descript,'�', 'D') 
FROM 
  tableT kk where pp.id=kk.id) ;
2个回答

21
update tableT pp
set descript = (select replace(descript, '�', 'D') from tableT where id = pp.id)
为什么不使用替换函数?

14

这只是一个普通的 UPDATE

update  tableT set descript= regexp_replace(descript,'�', 'D')

添加 where descript like '%�%' 来最小化交易。

或者,如卡莫总统所说,为什么不使用 replace 而不是 regexp_replace 呢?


3
在添加的 WHERE 上加 1 - Erwin Brandstetter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接