I was quite surprised when MySQL allowed me to insert a NULL
into a field that was created with NOT NULL
. I did some research and discovered how to enable strict mode. However, I am not quite sure what validation MySQL does when STRICT_ALL_TABLES
is enabled.
The manual says:
Strict mode controls how MySQL handles input values that are invalid or missing. A value can be invalid for several reasons. (emphasis mine) For example, it might have the wrong data type for the column, or it might be out of range.
I understand what it considers missing and how it handles that. I am unclear what it considers invalid. I've done some testing and discovered the following:
- strings that are too long are invalid
- numbers that are out of range are invalid
NULL
s for a non-NULL
column are invalidTRUE
andFALSE
always seem to be valid (they become 1 and 0 respectively)- invalid dates are invalid
- zero dates are valid (additional modes can be enabled to change this behaviour)
- floats in an integer field are valid (they get rounded)
- letters in a number field are invalid
Does MySQL do any other validation checks other than what is mentioned above?
The manual says 'wrong data type for the column', but the only situation I see where this actually comes into play is letters in a number field. Are there other examples of data type errors?
Is there a list somewhere of exactly what checks MySQL performs?
EDIT: For the record, my application already does extensive validation. I am using strict mode as a last-chance, just-in-case check. If I forget to check something, I want it to fail fast rather than 'silently mangle my data'.