postgresql Postgres 替换字符串中的字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28696915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres replace characters in string
提问by user238271
I have column with text where I need to change characters! For example
我有需要更改字符的文本列!例如
- ?ay----> need to be Day
- ?rag---->need to be Drag
- ?ay----> 需要是 Day
- ?rag---->需要拖动
So I need to replace ? with character D. I try next but I get error:invalid regular expression: quantifier operand invalid
所以我需要更换?与字符 D. 我尝试下一个但我得到错误:无效的正则表达式:量词操作数无效
update tableT pp set descript=(select regexp_replace(descript,'?', 'D')
FROM
tableT kk where pp.id=kk.id) ;
回答by President Camacho
update tableT pp
set descript = (select replace(descript, '?', 'D') from tableT where id = pp.id)
Why don't use replace?
为什么不使用替换?
回答by jarlh
It's just a plain UPDATE
:
这只是一个普通的UPDATE
:
update tableT set descript= regexp_replace(descript,'?', 'D')
add where descript like '%?%'
to minimize transaction.
添加where descript like '%?%'
以最小化交易。
Or, as President Camacho says, why not use replace
instead of regexp_replace
?
或者,正如卡马乔总统所说,为什么不使用replace
代替regexp_replace
?