I'd like to change
{foo, {bar}, foobar}
to
{foo, bar, foobar}
in all rows that match '{.*{'
. I.e. remove all curly braces { and } except the outer most pair.
So doing
mysql -h $H -u $U -p$P $DB -B -e "SELECT id FROM t WHERE col REGEXP '{.*{'" > bad.txt
selects all the rows that will need this substitution. How do I make this substitution very quickly?
EDIT:
Could I do it by
update table set column = REPLACE(column,'{','');
Then restore the out most pair
update table set column = REPLACE(column,'^','{');
update table set column = REPLACE(column,'$','}');
I get error
mysql> EXPLAIN UPDATE t SET col=REPLACE(REPLACE(REPLACE(REPLACE(col,'{{','{'),'}}','}'), ', {', ', '), '}, ', ', ');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE t SET col=REPLACE(REPLACE(REPLACE(REPLACE(' at line 1