Postgresql:在更新時替換部分字符串

[英]Postgresql: replace part of string on update


I have 5000 plus records where I need to remove part of the value of a field

我有5000多條記錄,我需要刪除部分字段的值

In all cases, the part I wish to remove is "Job Description - "

在所有情況下,我想刪除的部分是“職位描述 - ”

Hence update so that "Job Description - Doctor" becomes "Doctor"

因此更新,以便“工作描述 - 醫生”成為“醫生”

So (I guess) I am looking to

所以(我猜)我期待

UPDATE mytable 
    SET myfield = {some regex} 

where myfield like '%Job Description - %'

myfield喜歡'%職位描述 - %'

Any advice would be much appreciated

任何建議將不勝感激

1 个解决方案

#1


1  

The answer is as follows:

答案如下:

UPDATE mytable 
  SET myfield = REPLACE(myfield, 'Job Description - ','');

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/02/17/72fa04f26d895f1f4006aaead3a50efb.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com