I have an actor
table that looks like this:
| actor_id | first_name | last_name | last_update |
+----------+------------+-----------+---------------------+
| 1 | Jack | Nicholson | 2019-06-02 00:00:00 |
Column actor_id
is a primary key with auto increment.
When I try to update the table like so:
UPDATE actor
SET last_name = 'foo'
WHERE last_update > '2019-06-02 00:00:00';
I get blocked by MySQL's safe update mode with this error:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.
Indeed column last_update
is not a KEY column, so based on this SO answer I've come up with the following workaround:
CREATE TEMPORARY TABLE IF NOT EXISTS ids AS (SELECT actor_id FROM actor WHERE last_update > '2019-06-02 00:00:00');
UPDATE actor
SET last_name = 'foo'
WHERE actor_id IN (SELECT actor_id FROM ids);
But again I'm blocked with a 1175 error.
Why is safe update mode blocking me here? Can I work around it without disabling safe update mode?