Viewing 8 replies - 1 through 8 (of 8 total)
  • McShelby

    (@mcshelby)

    Are you looking for something like this:


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

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

    McShelby

    (@mcshelby)

    Oh sorry, it was:

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

    Thread Starter Mark (podz)

    (@podz)

    I’m having problems …

    UPDATE wp_posts
    SET post_content=(
    REPLACE(
    post_content,
    https://the.old.domain/img/%/%/%/”,
    https://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 ?

    McShelby

    (@mcshelby)

    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 https://dev.mysql.com/doc/refman/4.1/en/regexp.html

    UPDATE wp_posts
    SET post_content = "https://www.the-new-domain.com/images/"
    WHERE post_content REGEXP ".*https://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.

    McShelby

    (@mcshelby)

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

    Thread Starter Mark (podz)

    (@podz)

    Thanks for trying – it’s appreciated ??

    Thread Starter Mark (podz)

    (@podz)

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

    McShelby

    (@mcshelby)

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Can SQL do this ?’ is closed to new replies.