Database Maintenance – image url replacement in post content

use www_wuyifan;
MariaDB [www_wuyifan]> select ID from wp_posts where post_content like '%https://www.wuyifan.com/wp-content/uploads%' and post_content like '%img%'

check / test one entry where ID = 1009

UPDATE wp_posts SET post_content=(REPLACE (post_content, 'https://www.wuyifan.com/wp-content/uploads/','https://voip.wuyifan.com/wp-content/uploads/')) where ID = 1009;

UPDATE wp_posts SET post_content=(REPLACE (post_content, 'https://www.wuyifan.com/wp-content/uploads/','https://voip.wuyifan.com/wp-content/uploads/')) where ID IN (select ID from wp_posts where post_content like '%https://www.wuyifan.com/wp-content/uploads%' and post_content like '%img%');

ERROR 1093 (HY000): You can't specify target table 'wp_posts' for update in FROM clause

MariaDB [www_wuyifan]> UPDATE wp_posts SET post_content=(REPLACE (post_content, 'https://www.wuyifan.com/wp-content/uploads/','https://voip.wuyifan.com/wp-content/uploads/')) where ID IN (1006, 938);
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

https://www.geeksforgeeks.org/mysql-cant-specify-target-table-for-update-in-from-clause/

Using a Temporary Table as a Workaround

MariaDB [www_wuyifan]> CREATE TEMPORARY TABLE aaa AS select ID from wp_posts where post_content like '%https://www.wuyifan.com/wp-content/uploads%' and post_content like '%img%';
Query OK, 200 rows affected (0.02 sec)
Records: 200  Duplicates: 0  Warnings: 0
200 rows in set (0.00 sec)

MariaDB [www_wuyifan]> select * from aaa limit 1;
+-----+
| ID  |
+-----+
| 174 |
+-----+

MariaDB [www_wuyifan]> UPDATE wp_posts SET post_content=(REPLACE (post_content, 'https://www.wuyifan.com/wp-content/uploads/','https://voip.wuyifan.com/wp-content/uploads/')) where ID IN (select ID from aaa);                                                                                   Query OK, 200 rows affected (0.19 sec)
Rows matched: 200  Changed: 200  Warnings: 0

MariaDB [www_wuyifan]> drop table aaa;
Query OK, 0 rows affected (0.00 sec)