postgresql 中的varchar字段怎么利用regexp_replace正则进行替换

发布时间:2021-01-08 16:04:37 作者:Leah
来源:亿速云 阅读:369

postgresql 中的varchar字段怎么利用regexp_replace正则进行替换?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

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"

补充:PostgreSql  regexp_replace 替换括号里面所有字符串

我就废话不多说了,大家还是直接看代码吧~

// PG 数据 替换数据中的 例如(1222-2) 中的所有值
select regexp_replace('在激励(1222-2)','(\(.*\))','','')

关于postgresql 中的varchar字段怎么利用regexp_replace正则进行替换问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

推荐阅读:
  1. postgresql varchar字段regexp_replace正则替换
  2. postgresql在cast指的是什么

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

postgresql regexp replace varchar

上一篇:如何学习laravel

下一篇:yii2如何访问控制器

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》