David542
David542

Reputation: 110083

SQL UPDATE to do string replacement

I have some columns like:

Provider            url                                                       id       
Apple               https://s3.amazonaws.com/my-bin/APPLE_MAY2011.xls         1
HP                  https://s3.amazonaws.com/my-bin/HP_MAY2011.xls            2

I changed one of the S3 bins and now need to change the url for all rows to be:

Apple               https://s3.amazonaws.com/mybin/APPLE_MAY2011.xls         1
HP                  https://s3.amazonaws.com/mybin/HP_MAY2011.xls            2

In other words, I need to change my-bin to mybin. How would I do this directly in SQL (instead of SELECTING everything and iterating and doing an INSERT for every row?)

Upvotes: 0

Views: 81

Answers (1)

SoEnLion
SoEnLion

Reputation: 183

You can use:

update TABLE_NAME set url = replace(url, 'my-bin', 'mybin');

Upvotes: 6

Related Questions