Reputation: 51
I am having trouble with replacing something in a column. I have the "posts" table with the "post_text" column (MediumText).
I want to replace "EXAMPLE:https://www.youtube.com/watch?v=ICaPQLTlguM" with [block]ICaPQLTlguM[/block].
I'm Blocked at the following SQL
UPDATE post SET post_text= REPLACE('post_text','https://www.youtube.com/watch?v=','[block]');
How can i incapsulate the video referrence id in the [block][/block] brakets ?
Upvotes: 1
Views: 44
Reputation: 64496
You can use concat
UPDATE post
SET post_text=
CONCAT(
REPLACE(post_text,'https://www.youtube.com/watch?v=','[block]')
,'[/block]'
);
Upvotes: 0
Reputation: 1270873
This is more complicated than a simple replace. Perhaps you want this:
UPDATE post
SET post_text = CONCAT('[block]',
substring_index(post_text, '=', -1),
'[/block]'
);
Upvotes: 1