Question

According to MySQL 5.5 documentation, the valid syntax for an UPDATE is the following:

UPDATE [LOW_PRIORITY] [IGNORE] table_references
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]

In our code we found this request:

UPDATE eMail SET Actif = 0 AND FKClient = 122;

The table is Innodb on a MySQL 5.5 and Actif is tinyint(1) nullable.

As far as I know this syntax is invalid and should not execute since the AND comparison is not permitted in a SET statement.

If you execute the code, all eMail rows will be set to Actif = 0.

Why does my UPDATE request work?

Was it helpful?

Solution

Sure it is. It's parsed as:

UPDATE eMAIL SET Active = (0 AND FKCLient = 122)

FKClient= 122 will be a boolean comparison, returning true/false, so it becomes

UPDATE eMAIL SET Active = (0 AND bool)

0 AND anything is 0, so..

... SET Active = 0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top