0

I have a row with content that can look like this:

bla bla bla [ATTACH]123456[/ATTACH] bla bla bla
bla bla bla [ATTACH]78912[/ATTACH] bla something bla

I need to search the row for all occurences of [ATTACH]number[/ATTACH] and replace it like this:

[ATTACH]123456[/ATTACH] should become [sharedmedia=core:attachments:123456]

or...

[ATTACH]78912[/ATTACH] should become [sharedmedia=core:attachments:78912]

2
  • Great. Looks like fun.
    – Strawberry
    Commented Mar 15, 2014 at 16:02
  • Thank you for providing a report on the status of your current efforts. Did you have a question? Commented Mar 15, 2014 at 16:13

1 Answer 1

1

SQL is not optimized for this sort of work. The following might accomplish what you want:

update table t
    set content = replace(replace(content, '[ATTACH]', '[sharedmedia=core:attachments:'
                                 ), '[/ATTACH]', ']'
                         )
    where content like '[ATTACH]%[/ATTACH]';

This assumes that all occurrence of [ATTACH] are followed by a number.

2
  • @Akyhne . . . That is why I always try to line up my parentheses, so I can visually see when I might be missing one. Commented Mar 15, 2014 at 16:17
  • Works this way: update table t set content = replace(replace(content, '[ATTACH]', '[sharedmedia=core:attachments:' ), '[/ATTACH]', ']' ) where content like '%[ATTACH]%[/ATTACH]%'; This assumes that all occurrence of [ATTACH] are followed by a number.
    – Akyhne
    Commented Mar 15, 2014 at 16:28

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.