Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql: replace part of string on update

Tags:

sql

postgresql

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

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 - %'

Any advice would be much appreciated

like image 766
Jake Avatar asked Feb 17 '17 06:02

Jake


1 Answers

The answer is as follows:

UPDATE mytable 
  SET myfield = REPLACE(myfield, 'Job Description - ','');
like image 144
Jake Avatar answered Oct 11 '22 19:10

Jake