postgresql varchar字段regexp_replace正則替換

1.替換目標
1).contact字段類型 varchar。
2).去掉字段中連續的兩個,每一個等號後面數字不一樣,effective_caller_id_name=051066824513,effective_caller_id_number=051066824513。app

2.查詢原字段內容ide

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

"{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 (...)"regexp

3.查詢語句驗證替換ip

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

"{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"it

4.執行替換操做io

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

where contact ~ 'effective_caller_id_name=' date

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"

相關文章
相關標籤/搜索