Comments - Datetime behavior in MariaDB vs MySQL

5 years, 11 months ago Ian Gilfillan

MariaDB considers all badly formatted strings as '0000-00-00 00:00:00' for comparison purposes. Current versions of MySQL are inconsistent, in that they handle constants one way, and non-constants another way.

Consider the following example from MySQL, with confusing results:

SET sql_mode='';
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a FLOAT, b DATETIME, c TIME, d VARCHAR(10));
INSERT INTO t1 VALUES ( 111.222, '23Apr75', '05May99', 'a');
SELECT * FROM t1 WHERE b='31Jan1999';
SELECT * FROM t1 WHERE b=IF(RAND(),'31Jan1999','31Jan1999');

SELECT * FROM t1 WHERE b='31Jan1999';
Empty set, 2 warnings (0.00 sec)

SELECT * FROM t1 WHERE b=IF(RAND(),'31Jan1999','31Jan1999');
+---------+---------------------+----------+------+
| a       | b                   | c        | d    |
+---------+---------------------+----------+------+
| 111.222 | 0000-00-00 00:00:00 | 00:00:05 | a    |
+---------+---------------------+----------+------+
1 row in set, 1 warning (0.00 sec)
 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.