{"id":35,"date":"2006-11-30T11:10:07","date_gmt":"2006-11-30T11:10:07","guid":{"rendered":"http:\/\/www.nostuff.org\/words\/?p=35"},"modified":"2006-11-30T11:10:07","modified_gmt":"2006-11-30T11:10:07","slug":"sql-update-doing-a-findreplace-on-part-of-a-field","status":"publish","type":"post","link":"https:\/\/www.nostuff.org\/words\/2006\/sql-update-doing-a-findreplace-on-part-of-a-field\/","title":{"rendered":"SQL update: doing a find\/replace on part of a field"},"content":{"rendered":"<p>SQL is one of those things I rarely use, and it&#8217;s normally the simple stuff, but doing anything a little more complex can be non-obvious. For example, I had a bunch of URLs where I just need to update a part of the URL, as we were moving some files on a website. I eventually found what I wanted within the <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/update.html\">comments to the MySQL UPDATE command documentation<\/a>. (credit to Alex de Landgraaf on July 21 2004):<\/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>UPDATE table<br \/>\nSET fieldname=(<br \/>\nREPLACE (fieldname,<br \/>\n&#8216;\/somedir\/images\/&#8217;,<br \/>\n&#8216;\/newhome\/graphics\/&#8217;));<br \/>\nDoes the trick nicely on MySQL :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL is one of those things I rarely use, and it&#8217;s normally the simple stuff, but doing anything a little more complex can be non-obvious. For example, I had a bunch of URLs where I just need to update a part of the URL, as we were moving some files on a website. I eventually [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":0,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}