[nSLUG] MySQL find/replace

Miles Thompson milesthom at gmail.com
Sat Jun 26 21:50:05 ADT 2010


Did you have a look at IS NULL and isnull() ?
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

It's a trap I've fallen into before - "NULL" is not a real null, it's a
string.

How about this, untested of course:
update wp_postmeta set meta_key = "my replacement text" where
isnull(meta_key);

Cheers - Miles

On Sat, Jun 26, 2010 at 7:14 PM, Herb <htheriault at gmail.com> wrote:

> Hi all,
>
> I'm migrating an aging drupal site to wordpress and am stuck on one of
> my last sql tasks, involving replacing a field in one of the mysql
> tables.
>
>
> =======
> mysql> update wp_postmeta set meta_key = replace(meta_key,"NULL","my
> replacement text");
> Query OK, 0 rows affected (0.00 sec)
> Rows matched: 549  Changed: 0  Warnings: 0
> =======
>
> It's matching the entire column instead of the fields that are NULL
>
> Attempts at changing the first bracketed field to NULL as well
> ("NULL","NULL","my replacement text") actually fills the column with
> the replacement.
>
> Can anyone shed some light on what I'm missing?
>
> Thanks,
>
> Herb
> _______________________________________________
> nSLUG mailing list
> nSLUG at nslug.ns.ca
> http://nslug.ns.ca/mailman/listinfo/nslug
>



-- 
Miles Thompson
~~~~~~~~~~~~~~~~~~~~~~~~~~
"The piano keys are black and white,
But they sound like a million colours in your mind"
Spider's Web - Katie Melua
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/mailman/private/nslug/attachments/20100626/cb958266/attachment-0002.html>


More information about the nSLUG mailing list