1

Suppose I have the following MySQL data

  1. userfiles/user/JohnSmith/2013_Thanksgiving_Final.jpg
  2. userfiles/user/JaneJohnson/2013_Thanksgiving_Final.jpg
  3. userfiles/user/BobbyLee/2013_Thanksgiving_Final.jpg

Is there a way to change it to?

  1. globalfiles/2016_Thanksgiving_Final.jpg
  2. globalfiles/2016_Thanksgiving_Final.jpg
  3. globalfiles/2016_Thanksgiving_Final.jpg

I was thinking doing something like this?

 UPDATE user__attributes SET value = REPLACE(value, REGEXP '2013_Thanksgiving_Final', 'globalfiles/2016_Thanksgiving_Final.jpg') WHERE value LIKE '%2013_Thanksgiving_Final%';

I was thinking if I used REGEXP, it would target the whole string, based off just a piece of it to replace? Though I threw an error attempting this.

Thanks!

1
  • you want remove the part 'yserFiles/user/JohnSmith/ and repalce with globlfiles for all the user where there is 2013_Thanksgiving_Final.jpg? Commented Oct 27, 2016 at 15:50

1 Answer 1

1

If you want add globalfiles at existing files name the You don't need regexp but simply replace

UPDATE user__attributes 
SET value = REPLACE(value, '2013_Thanksgiving_Final.jpg', 'globalfiles/2016_Thanksgiving_Final.jpg' ) 
WHERE value LIKE '%2013_Thanksgiving_Final%';

if you want substitute the userfiles/user/*/2013_Thanksgiving_Final.jpg with globalfiles/2016_Thanksgiving_Final.jpg you should use

UPDATE user__attributes 
SET value = globalfiles/2016_Thanksgiving_Final.jpg
WHERE value LIKE '%2013_Thanksgiving_Final%';
Sign up to request clarification or add additional context in comments.

1 Comment

Ah I was going about it all wrong, thank you for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.