首页数据库postgresql varchar字段regexp

postgresql varchar字段regexp

时间2024-02-29 15:42:03发布访客分类数据库浏览681
导读:收集整理的这篇文章主要介绍了postgresql varchar字段regexp_replace正则替换操作,觉得挺不错的,现在分享给大家,也给大家做个参考。 1.替换目标1).cont...
收集整理的这篇文章主要介绍了postgresql varchar字段regexp_replace正则替换操作,觉得挺不错的,现在分享给大家,也给大家做个参考。

1.替换目标

1).contact字段类型 vArchar。

2).去掉字段中连续的两个,每个等号后面数字不同,

effective_caller_id_name=051066824513,effective_caller_id_number=051066824513

2.查询原字段内容

select contactFrom pbx_agentswhere 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_agentswhere 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 contactfrom 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 regexp_matches替换like模糊查询的操作
  • postgresql 替换空格 换行和回车的操作
  • PostgreSQL 正则表达式替换-使用变量方式
  • postgresql 实现将字段为空的值替换为指定值

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: postgresql varchar字段regexp
本文地址: https://pptw.com/jishu/633059.html
PostgreSQL11修改wal-segsize的操作 php中setcookie函数的作用是什么

游客 回复需填写必要信息