溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

postgresql 中的varchar字段怎么利用regexp_replace正則進行替換

發(fā)布時間:2021-01-08 16:04:37 來源:億速云 閱讀:383 作者:Leah 欄目:開發(fā)技術

postgresql 中的varchar字段怎么利用regexp_replace正則進行替換?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

1.替換目標

1).contact字段類型 varchar。

2).去掉字段中連續(xù)的兩個,每個等號后面數(shù)字不同,

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.執(zhí)行替換操作

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 數(shù)據(jù) 替換數(shù)據(jù)中的 例如(1222-2) 中的所有值
select regexp_replace('在激勵(1222-2)','(\(.*\))','','')

關于postgresql 中的varchar字段怎么利用regexp_replace正則進行替換問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業(yè)資訊頻道了解更多相關知識。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI