4

I don't have this kind of ID in my table, still MySQL is giving me a result. This same result is giving when i place in my php code. enter image description here

  • 1
    Welcome to the weird MySQL world where 182 equals 182&*^&*%*%**^%%%^@~##; – ypercubeᵀᴹ Jan 16 '14 at 12:03
  • but if i have to place this query in my php code, than also this is giving me a same result – SagarPPanchal Jan 16 '14 at 12:05
  • could be a memory leak... – RolandoMySQLDBA Jan 16 '14 at 17:30
  • 3
    What data type is your garbledgarbledgarbled_id column? – Shlomi Noach Jan 16 '14 at 18:31
  • 2
    And why (if the garbled_id column is Integer) are you comparing it to a string? – ypercubeᵀᴹ Jan 16 '14 at 23:33
8

I am always majorly impressed by MySQL. It seems that in order to do the the type comparison, MySQL implicitly converts the string literal you are passing to the where clause to an unsigned integer. Through the mechanics of the implementation of the MySQL CONVERT function, the datatype switch simply cannot fail, in this case, giving you the 182 value. The links show a few examples of the CONVERT function behaving, well, badly, imo.

13

Some DBMS are omnipotent and merciless. They give numerous warnings and errors in all kinds of situations when a user is attempting the slightest deviation from the correct behaviour - defined by the standards and the DBMS documentation.

MySQL is merciful and all-loving. She is trying to help everyone. Even if someone is comparing a string to an integer, she's thinking that the user may know better what he is doing and that maybe he is right. Not wanting to let him go in despair, she is trying - against all consistency and integrity laws - to compare the 2 incomparable things.

And - oh, the miracle - sometimes the 2 things are the same after all! What if one is the number 182 (which comes from an id column, stored in 4 bytes) and the other is the string 182^%^&$$%$%$sjfhjs ^%^&%&*^$^%$^$ which needs 28. They look the same anyway, when the second is truncated from those silly characters!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.