I am working on some PHP code optimization and while I am going through I find some SELECT statements with the following conditions:
WHERE `date_exported` = '0000-00-00 00:00:00' OR `date_exported` IS NULL
This makes me wonder whether the same statement will work the same with only one condition: the comparison to NULL or the comparison against an "invalid" datetime.
I will add on top of that: using MySQL Workbench and Datagrip (or the equivalent from tools like PhpStorm) I am not able to see the column with NULL
but 0000-00-00 00:00:00
. I am not sure if this is a configuration thing or if it is supposed to be like that.
This is MySQL 5.7 and I do not have permission to check on config stuff or insights on how this instance is configured.
I have tried to set a playground here but it won't allow me to add 0000-00-00 00:00:00
in a NULL datetime
column
The SQL_MODE
is set as follows:
NO_ZERO,IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Note: is it 0000-00-00 00:00:00
invalid at all?
SHOW VARIABLES LIKE "SQL_MODE";
And look forNO_ZERO_DATE
.