error appear when I execute a SQL request - mysql

I have a SQL request that I can't execute ,this error appear:
To disable safe mode, toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect.
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
My request:
update customfieldvalue
set stringvalue="****"
where customfieldvalue.customfield IN
(select customfield.id
from customfield
where customfield.cfname="Resoltion"
and customfieldvalue.issue=12345);
how can I fix this problem,because in my production environment I can't do this manipulation?
PS:I'am using mysql

To disable it just for the current session run:
SET SQL_SAFE_UPDATES=0;

To fix this problem:
To disable safe mode:
Toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect.
The cause:
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
(Did you read the message? It explains everything)

If you can't turn off safe update in production, you'll need to rework your query to involve at least one key column in customfieldvalue. Without it, you'll be performing a table scan; using key column #1, you might end up with the logical equivalent ( WHERE customfieldvalue.keycol1 IS NOT NULL ), but that will satisfy the safe update constraints.

SET SQL_SAFE_UPDATES=0;
update customfieldvalue
set stringvalue="****"
where customfieldvalue.customfield IN
(select customfield.id
from customfield
where customfield.cfname="Resoltion"
and customfieldvalue.issue=12345);

Related

How to delete when primary key contains two columns, and using safe mode

My table is created like this:
CREATE TABLE test(
num1 INT,
num2 INT,
PRIMARY KEY(num1, num2)
);
what should my delete query look like?
using
DELETE FROM test WHERE num1=1 AND num2=2;
only result in this error message:
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.
Also, before you ask, I do know how to turn safe update mode off, but that does not answer my question.
I've seen some other Stack Overflow posts where people complain that MySQL Workbench is blocking them from performing safe updates inappropriately.
But I just tried it with your table, both with the PK columns and with a non-key column. When safe mode is enabled, it blocks me from doing updates via non-key column, as it should. But I don't get the error you described.
I'm using MySQL Workbench 6.3.8 and MySQL Server 8.0.0-dmr.
Perhaps this is a bug in an old version of MySQL or an old version of MySQL Workbench.
Updated mysql and the error is gone.
what a waste of my time.

MySQL error code: 1175 during UPDATE (MySQL-Workbench vs. console)

Am very aware of that this issue can be resolved with disabling safe update mode enabled (e.g. see here: MySQL error code: 1175 during UPDATE in MySQL Workbench). However, I do not wish to disable safe update mode (and there are many many solutions that propose this).
Similarly, I am aware that setting the WHERE clause to KEY-value that matches everything is supposed to work. However, doesn't appear to work on mysql-workbench - at least not the way I hoped (or the way it did work on the console).
For example, the following didn't work on mysql-workbench (but did on the console):
UPDATE FUEL_SOURCES AS FS
INNER JOIN
FUEL_CATEGORY FC ON FC.FUEL_CATEGORY = FS.FUEL_CATEGORY
SET
FS.FUEL_CATEGORY_ID = FC.ID
WHERE
FC.ID <> 0 AND FS.ID <> 0
...If I explicitly / exactly set the ID's (e.g. WHERE FC.ID = 20 AND FS.ID <> 10 for example) it would work in mysql-workbench. But doing this would involve iterating through every key-pair combination.
Be intereted to know what is causing this behaviour, or if I am doing something horribly wrong. Using mysql-workbench 6.3
From https://dev.mysql.com/doc/workbench/en/workbench-faq.html#faq-workbench-delete-safe
By default, Workbench is configured to not execute DELETE or UPDATE
queries that do not include a WHERE clause on a KEY column.
Such configuration prevents you from deleting or updating table mistakenly, since you are doing a batch update on data without a key.
To resolve this, as you may be already aware the following options.
Open your Workbench Preferences, select the SQL Editor section, and disable the following preference: "Safe Updates" - Forbid UPDATEs and DELETEs with no key in WHERE clause or no LIMIT clause.
Run SET SQL_SAFE_UPDATES=0;
If you are using workbech, you can first execute
SET SQL_SAFE_UPDATES = 0;
And then execute delete statement
If you want to still update your data with safe update on, you must retool your where clause so that it includes references to the table's primary key(s). See this page.

How to use replace to update the column items

I'd like to change the ',' char into '.' at one of my column . I can make the replace syntax but it just a view. And i want to update it for the all records!
select cast(replace(egysegar,',','.')as decimal (10,3)) from temporary
i'll tried the next one to update
UPDATE temporary set egysegar = replace(egysegar,',','.') where egysegar is not null
but after i get an error :
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 Queries and reconnect.
Most probably you're using MySQL Workbench and you actually have to disable the safe mode or add in the WHERE clause a key column, exactly as it says in the message.
Or you can run SET SQL_SAFE_UPDATES=0; before your update query.
Possible answer is that MySql run with safe-updates option. It mean you can't update or delete record without key primary key on where clause.
SET SQL_SAFE_UPDATES=0;
or use primary key in where clause

Getting error when tried to update a table using stored procedure in mysql

UPDATE IDConfig SET FemaleID = FemaleID + 1;
Getting Error like 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 Queries and reconnect.
Your SQL tool uses this mechanism to tell you that you are about to update ALL records in a table. Normally you have a WHERE clause to limit the data that should be updated.
So to really update ALL records change that option in the configuration or use a WHERE clause to limit your data to update.
You probably can trick your tool with this query
UPDATE IDConfig
SET FemaleID = FemaleID + 1
WHERE 1 = 1

mysql workbench cannot : update where like

Normally i can update my rows w/ queries such as
UPDATE t SET col1='123' WHERE col2 LIKE '%abc%';
or
UPDATE mydb.t SET col1='123' WHERE col2 LIKE '%abc%';
But with MySQL Workbench I seem to only be able to SELECT but cannot UPDATE the tables with queries.
Does anyone know a fix for working with workbench?
FIX
To disable safe mode, toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect.
Mysql workbench usually disables by default updates without a where clause, and/or updates that hit more than a configured X elements.
When you try to update and fail, if it is how I think it is, then pay attention to the error message, as it tells you exactly which setting to change.