Forums

Can SQL do this ? (9 posts)

  1. Mark (podz)
    Support Maven
    Posted 6 years ago #

    Is it possible to use phpmyadmin and replace this: http://one.two.com/three/xxx/yyy/zzz/
    with this
    http://domain.com/images/

    If so, what would the query be ?

  2. McShelby
    Member
    Posted 6 years ago #

    Are you looking for something like this:


    UPDATE table
    SET field =
    REPLACE("http://one.two.com/three/xxx/yyy/zzz/", "http://domain.com/images/");

    This should work with MySQL but I am not sure if this works with other DB systems.

  3. McShelby
    Member
    Posted 6 years ago #

    Oh sorry, it was:

    UPDATE table
    SET field =
    REPLACE(
    field,
    "http://one.two.com/three/xxx/yyy/zzz/",
    "http://domain.com/images/");

  4. Mark (podz)
    Support Maven
    Posted 6 years ago #

    I'm having problems ...

    UPDATE wp_posts
    SET post_content=(
    REPLACE(
    post_content,
    "http://the.old.domain/img/%/%/%/",
    "http://www.the-new-domain.com/images/"))

    as the /xxx/yyy/zzz in the example vary, so I used % as a wildcard. But ... when I run that, it says 0 rows changed, yet what I have between the "" is correct.
    What am I missing ?

  5. McShelby
    Member
    Posted 6 years ago #

    I expect this not to work, because the % wildcard will only work in WHERE statements. But you may modify the statement by using the MySQL regular expression support http://dev.mysql.com/doc/refman/4.1/en/regexp.html

    UPDATE wp_posts
    SET post_content = "http://www.the-new-domain.com/images/"
    WHERE post_content REGEXP ".*http://the.old.domain/img/alpha*/alpha*/alpha*/.*"

    I haven't tested this nor am I sure the regular expression does the job for you. You may have to extend the expected characters between the path separators as well.

  6. McShelby
    Member
    Posted 6 years ago #

    Okay, this will also not solve your problem and it seems that there is currently no pure SQL way to do this: http://forums.mysql.com/read.php?20,54128,54199

  7. Mark (podz)
    Support Maven
    Posted 6 years ago #

    Thanks for trying - it's appreciated :)

  8. Mark (podz)
    Support Maven
    Posted 6 years ago #

    Ahh....... export .sql, do regex replace, import .sql ?

  9. McShelby
    Member
    Posted 6 years ago #

    This may work. In this case you'd only need a texteditor with regex capabilities.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags