{"id":764,"date":"2005-08-04T23:13:00","date_gmt":"2005-08-05T04:13:00","guid":{"rendered":"http:\/\/blogs.terrorware.com\/geoff\/2005\/08\/04\/howto-replacing-a-substring-in-a-column-value-with-a-mysql-query\/"},"modified":"2005-08-04T23:13:00","modified_gmt":"2005-08-05T04:13:00","slug":"howto-replacing-a-substring-in-a-column-value-with-a-mysql-query","status":"publish","type":"post","link":"http:\/\/blogs.terrorware.com\/geoff\/2005\/08\/04\/howto-replacing-a-substring-in-a-column-value-with-a-mysql-query\/","title":{"rendered":"howto: replacing a substring in a column value with a MySQL query"},"content":{"rendered":"<p><a href=\"http:\/\/dev.mysql.com\/doc\/mysql\/en\/update.html\">MySQL Reference Manual :: 13.2.10 UPDATE Syntax<\/a>: &#8220;You sometimes run into the problem that you want to replace a substring occuring in a column with a different string, without touching the rest of the string. The solution is surprisingly simple, thanks to MySQL:<\/p>\n<p>UPDATE xoops_bb_posts_text<br \/>\nSET post_text=(<br \/>\nREPLACE (post_text,<br \/>\n&#8216;morphix.sourceforge.net&#8217;,<br \/>\n&#8216;www.morphix.org&#8217;));<\/p>\n<p>using the string function REPLACE, all items in the post_text column with &#8216;morphix.sourceforge.net&#8217; get this substring replaced by &#8216;www.morphix.org&#8217;. Ideal when writing a script is just too much effort.&#8221;<\/p>\n<p>This will be useful for changing a bunch of text on the various wiki pages for <a href=\"http:\/\/pixfestdoc.terrorware.com\/\">pixfestdoc.terrorware.com<\/a>. I had a bunch of links that read &#8216;View\/Upload Photos&#8217; and I want to change them to &#8216;View\/Upload Photos and Video&#8217;. This would have sucked to do through a web interface, but messing with the database should make it quick.  I ran into a little problem with the Mediawiki handles caching so the changes didn&#8217;t show up right away, but I waited overnight and it worked out.<\/p>\n<p>UPDATE:  This the query that I used to add additional text to all the show pages:<\/p>\n<p>update pixfestmw_cur set cur_text=(concat(&#8216;== Photos\/Video ==\\n\\n&#8217;, concat(cur_text, &#8216;\\n\\n== Audio ==\\n\\n== Stories ==\\n\\nTo read stories from this show, please click on the \\&#8217;discussion\\&#8217; tab at the top of this page.\\n\\n== External Links ==&#8217;))) where cur_title like &#8216;%June_%&#8217;;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL Reference Manual :: 13.2.10 UPDATE Syntax: &#8220;You sometimes run into the problem that you want to replace a substring occuring in a column with a different string, without touching the rest of the string. The solution is surprisingly simple, thanks to MySQL: UPDATE xoops_bb_posts_text SET post_text=( REPLACE (post_text, &#8216;morphix.sourceforge.net&#8217;, &#8216;www.morphix.org&#8217;)); using the string function&hellip; <a class=\"more-link\" href=\"http:\/\/blogs.terrorware.com\/geoff\/2005\/08\/04\/howto-replacing-a-substring-in-a-column-value-with-a-mysql-query\/\">Continue reading <span class=\"screen-reader-text\">howto: replacing a substring in a column value with a MySQL query<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-764","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4wnIz-ck","_links":{"self":[{"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/posts\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/comments?post=764"}],"version-history":[{"count":0,"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/posts\/764\/revisions"}],"wp:attachment":[{"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/media?parent=764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/categories?post=764"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blogs.terrorware.com\/geoff\/wp-json\/wp\/v2\/tags?post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}