Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL query to replace part of field in PHPMyAdmin

Author  Topic 

harveylester
Starting Member

1 Post

Posted - 2011-11-27 : 12:00:02
Hi,

I have a table called 'wp_postmeta' (Wordpress) which contains a column called 'meta_value'. A typical field in this column looks like this:

a:22:{s:12:"productimage";s:104:"http://www.disobeyclothing.com/wp-content/themes/eCommerce3/images/tshirts/SurveillanceSociety-Black.png";s:13:"productimage1";s:104:"http://www.disobeyclothing.com/wp-content/themes/eCommerce3/images/tshirts/SurveillanceSociety-White.png";s:13:"productimage2";s:0:"";s:13:"productimage3";s:0:"";s:13:"productimage4";s:0:"";s:13:"productimage5";s:0:"";s:13:"productimage6";s:0:"";s:5:"price";s:5:"10.50";s:12:"spPrdLstDate";s:0:"";s:12:"specialprice";s:4:"0.00";s:6:"weight";s:3:"250";s:9:"istaxable";s:0:"";s:4:"size";s:12:"S,M,L,XL,XXL";s:5:"color";s:11:"Black,White";s:10:"size_stock";s:5:",,,,,";s:11:"color_stock";s:2:",,";s:19:"is_check_outofstock";s:0:"";s:9:"initstock";s:0:"";s:8:"minstock";s:1:"0";s:11:"isshowstock";s:0:"";s:14:"affiliate_link";s:0:"";s:8:"posttype";s:7:"product";}


I'd like to replace all instances of 'http://www.disobeyclothing.com' with 'http://www.projectdisobey.com/disobeyclothing/uk'.

I've tried to run the following query but each time I run it, it wipes all data in the field:

UPDATE wp_postmeta set meta_value=replace(meta_value, 'http://www.disobeyclothing.com', 'http://www.projectdisobey.com/disobeyclothing/uk')


I've also tried this query, but it has the same effect:

UPDATE wp_postmeta 
SET meta_value = replace(LTRIM(RTRIM(meta_value)), 'http://www.disobeyclothing.com', 'http://www.projectdisobey.com/disobeyclothing/uk');


Any suggestions as to what I might be doing wrong (and how to do it right)?

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-27 : 13:31:22
Your first update statement looks correct. I am not sure why it would wipe out all data in the column as that would work in SQL Server land. Because you aren't using Microsoft SQL Server, which is what SQLTeam.com is about, it is really hard for us to help you. You should consider posting your question on a site that specializes in the technology you are using. Try dbforums.com for instance.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -