Search code examples
mysqlundefined-behavior

MySQL using "-" as different


It's not really a question, I already found out the answer the hard way. The problem is with the following query.

delete from <table> where id - 145;

Having minus instead of equals was clearly a typo. The database's autocommit was turned on and I ended up deleting all the entries in the table except those with the id = 145. So the minus over there acted as a "not equal" operator.

I searched for similar situations and looked for this operator in the MySQL docs and I couldn't find anything.

Is this supposed to happen this way? Is it normal or a MySQL bug?


Solution

  • delete from <table> where id - 145; 
    

    will work fine if id is 146 as 146-145=1 and mysql return true for 1 and false for 0;

    Hope this solve your doubt.