-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WordPress database error You can't specify target table 'wp_postmeta' / 'wp_termmeta' for update in FROM clause #1206
Comments
No one else encountered this problem it seems. What DB do you use? |
@yoancutillas could you tell which DB engine you are using, to understand if it's a specific case or more general? |
@spleen1981 What do you think about this? Did we miss some cases where this won't work for all DB? |
I would say no AFAIK, but it would be interesting to know what DB/engine this issue applies to... |
Ok, it seems current query works properly with MariaDB but generates the error above with MySQL. |
Fix MySQL error - You can't specify target table 'wp_postmeta' / 'wp_termmeta' for update in FROM clause qtranslate#1206
Interesting. In production I have MariaDB. But for development I have MySQL (in a docker container). With MySQL, I don't have the problem if I run the qTranslate code through PHP (8.0)... But, if I try a similar SQL command with phpMyAdmin, I can reproduce this! I tried with MySQL 5.7 and 8.0, it's the same. @spleen1981 did you manage to reproduce the error in PHP or phpMyAdmin? |
@herrvigg reproduced in phpMyAdmin |
When you wrote it works with MariaDB, did you also try it in phpMyAdmin? |
Yes it was in PHP, the SQL query failed during the plugin execution, and the logs you can see in the frist report were found in the PHP error log file. |
yes |
So the only consistent point is that MariaDB tolerates this. |
To be complete, it's possible only from MariaDB 10.3. It failed in MariaDB 10.2 (as for MySQL). |
So much fun with SQL, the fix can even fail due to the optimizer... https://stackoverflow.com/a/45498. |
I tried to reproduce it on PHP and in fact there's something, I see it but only as @yoancutillas In your case did the query really fail when run from PHP? Did it propagate as a PHP error (not notice or warning)? |
Improved the LIKE queries by escaping the |
Released in 3.12.1. |
In my case, the SQL query failed when run from the plugin's PHP code, the data didn't changed (just like when run from phpMyAdmin). It was not a PHP error nor a PHP warning, it was a log written by Wordpress into the PHP error log file to inform the developer that the SQL query has failed, with the mySQL error log message (which you can see is the same as in phpMyAdmin): So it doesn't prevent further PHP execution. Note that such messages don't appear if this code is executed somewhere before: |
Hello, I am getting an error right after migrating QTS Slugs:
The reason is probably that: https://stackoverflow.com/a/4562797
Indeed it is working properly if you replace slugs-migrate-qts.php line 73
$results = $wpdb->query( "DELETE FROM $table WHERE meta_key like '$new_prefix%' AND $colid in ($id_to_delete)" );
with
$results = $wpdb->query( "DELETE FROM $table WHERE meta_key like '$new_prefix%' AND $colid in ( SELECT * FROM ( $id_to_delete ) as M )" );
The text was updated successfully, but these errors were encountered: