postgresql varchar字段regexp_replace正则替换
admin
2023-05-21 13:42:38
0

1.替换目标
1).contact字段类型 varchar。
2).去掉字段中连续的两个,每个等号后面数字不同,effective_caller_id_name=051066824513,effective_caller_id_number=051066824513。

2.查询原字段内容

select contact
from pbx_agents
where contact ~ 'effective_caller_id_name=' limit 2

"{sip_append_audio_sdp=a=fmtp:18 annexb=no,call_timeout=60,effective_caller_id_name=051066824513,effective_caller_id_number=051066824513,cti_account=9,cti_agent_id=1102441276,cti_account_sid=5be394c3f8754bd89b9618937c687068,absolute_codec_string=\'OPUS,G729 (...)"
"{sip_append_audio_sdp=a=fmtp:18 annexb=no,call_timeout=60,effective_caller_id_name=051066824824,effective_caller_id_number=051066824824,cti_account=9,cti_agent_id=1103211003,cti_account_sid=4f3fae0e71b74bdaa3824e6ec7771815,absolute_codec_string=\'OPUS,G729 (...)"

3.查询语句验证替换

select regexp_replace(contact, '(effective_caller_id_name=\d+,)+?','','g')
from pbx_agents
where contact ~ 'effective_caller_id_name='

"{sip_append_audio_sdp=a=fmtp:18 annexb=no,call_timeout=60,effective_caller_id_number=051066824513,cti_account=9,cti_agent_id=1102441276,cti_account_sid=5be394c3f8754bd89b9618937c687068,absolute_codec_string=\'OPUS,G729\'}sofia/gateway/agentProxy/1102441276"
"{sip_append_audio_sdp=a=fmtp:18 annexb=no,call_timeout=60,effective_caller_id_number=051066824824,cti_account=9,cti_agent_id=1103211003,cti_account_sid=4f3fae0e71b74bdaa3824e6ec7771815,absolute_codec_string=\'OPUS,G729\'}sofia/gateway/agentProxy/1103211003"

4.执行替换操作

update pbx_agents set contact = regexp_replace(contact, '(effective_caller_id_name=\d+,)+?','','g')

where contact ~ 'effective_caller_id_name='

Query returned successfully: 3929 rows affected, 505 msec execution time.

5.查询验证替换

select contact
from pbx_agents

"{sip_append_audio_sdp=a=fmtp:18 annexb=no,call_timeout=60,cti_account=9,cti_agent_id=1100891004,cti_account_sid=23869df09f2f47f0ae80a7cbc45e5185,absolute_codec_string=\'OPUS,G729\'}sofia/gateway/agentProxy/1100891004"
"{sip_append_audio_sdp=a=fmtp:18 annexb=no,call_timeout=60,cti_account=9,cti_agent_id=1102081069,cti_account_sid=9f2c1574fcb5497994cb9b892aee0d1c,absolute_codec_string=\'OPUS,G729\'}sofia/gateway/agentProxy/1102081069"

相关内容

热门资讯

“救”在身边!4天2场“急”时... ▲红十字少年叶子豪与护士马莉开展紧急救援。台海网8月4日讯(导报记者 石程罗纳 通讯员 苏映红 陈雅...
Claude仅用8分钟,5年未... 新智元报道 25分钟,500个钱包被洗劫一空! 这几天,知名硬件钱包Coldcard暴雷,而引发这...
低价流量卡一夜消失!三大运营商... 最近几天,关于流量卡的讨论热度越来越高,原因很简单——流量卡没了。 最开始,只是有网友突然上传了一份...
薪火传家 执“戟”报国——王戟... 新华社长沙8月3日电 题:薪火传家 执“戟”报国——国防科技大学研究员王戟的家风故事新华社记者黄明、...
夏季战役第二阶段打响,乌方称俄... 据凤凰卫视报道,俄乌夏季战役第二阶段已经打响,顿巴斯中线多地陷入持续激战,俄军拿下了别列茨克定居点,...
顶尖AI人才争夺白热化 招聘逻... 图片来源:AI生成 证券时报记者 周春媚 财富的洪流永恒流动,但从不固守同一片河床,而是不断涌向新的...
婚外胚胎纠纷案,不容忽视的情理... 近日,上海一起婚外冷冻胚胎纠纷案持续搅动舆论漩涡。身患肺癌、长期休养的朱女士,意外发现丈夫与第三者伪...
抽水马桶水箱不进水的解决办法 步骤一、准备小刷子或是其他清洁工具;步骤二、打开水箱盖子;步骤三、将水箱的堵塞和污渍清理干净;步骤四...
马桶抽水后不停的流水怎么办 解决方法:水箱材质的问题,将马桶水箱拆分开来,一个一个逐一进行检查看是马桶水箱里面的零件是否完好,及...
马桶后面的抽水泵坏了怎么办 换一个新的。方法:先将坏的抽水泵拆卸下,把水箱下方的进水关闭,再通过扳手,一只手扶着水箱当中的进水阀...