I have a table that has a STATUS TINYINT(1) column and DEFAULT 0. All the records now have 0 for this column. When I query this with where status = 'active', the results seem to ignore this clause and return all the results. Is this the default behavior of SQL or MySQL?
1 Answer
What is happening is that MySQL is doing silent conversion. When a string is used in a numeric context, it is converted to a number, based on the leading digits.
There are no leading digits in 'active'. So, the value is converted to 0. Hence, your logic become (after the conversion):
status = 0
Pay attention to types and to the constants used for comparison.
2 Comments
TurtleTread
Is there a way to have MySQL not do this? like give out an error?
Gordon Linoff
I don't think so (although I am not 100% sure). There is an option to prevent the conversion when loading data into tables.