0

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 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to have MySQL not do this? like give out an error?
I don't think so (although I am not 100% sure). There is an option to prevent the conversion when loading data into tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.