[MDEV-11819] NO_ZERO_IN_DATE: Incorrect generated column value Created: 2017-01-16  Updated: 2017-10-06  Resolved: 2017-10-06

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types, Virtual Columns
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3
Fix Version/s: 5.5.58, 10.0.33, 10.1.29, 10.2.10, 10.3.2

Type: Bug Priority: Major
Reporter: Nirbhay Choubey (Inactive) Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-7635 update defaults and simplify mysqld c... Closed

 Description   

MariaDB [test]> set sql_mode = '';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> select timediff('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002');
+---------------------------------------------------------------------+
| timediff('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002') |
+---------------------------------------------------------------------+
| 46:58:57.999999                                                     |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [test]> drop table t1;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> CREATE TABLE `t1` (`a` datetime DEFAULT NULL, `b` datetime DEFAULT NULL, `c` time GENERATED ALWAYS AS (timediff(`a`,`b`)) VIRTUAL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> insert into t1 values ('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',default);
Query OK, 1 row affected (0.00 sec)
 
MariaDB [test]> select * from t1;
+---------------------+---------------------+----------+
| a                   | b                   | c        |
+---------------------+---------------------+----------+
| 2008-12-31 23:59:59 | 2008-12-30 01:01:01 | 46:58:58 |
+---------------------+---------------------+----------+
1 row in set (0.00 sec)
 
MariaDB [test]> set sql_mode='NO_ZERO_IN_DATE';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> drop table t1;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> CREATE TABLE `t1` (`a` datetime DEFAULT NULL, `b` datetime DEFAULT NULL, `c` time GENERATED ALWAYS AS (timediff(`a`,`b`)) VIRTUAL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> insert into t1 values ('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',default);
Query OK, 1 row affected (0.00 sec)
 
MariaDB [test]> select * from t1;
+---------------------+---------------------+------+
| a                   | b                   | c    |
+---------------------+---------------------+------+
| 2008-12-31 23:59:59 | 2008-12-30 01:01:01 | NULL | <---- Notice "NULL"
+---------------------+---------------------+------+
1 row in set (0.00 sec)



 Comments   
Comment by Alexander Barkov [ 2017-10-06 ]

The same problem is repeatable in this script:

SET sql_mode='NO_ZERO_IN_DATE';
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a TIME(6));
INSERT INTO t1 SELECT timediff(timestamp'2008-12-31 23:59:59.000001',timestamp'2008-12-30 01:01:01.000002');
SELECT * FROM t1;

+------+
| a    |
+------+
| NULL |
+------+

The expected result would be to store '46:58:57.999999' instead of NULL in the column.

Generated at Thu Feb 08 07:52:54 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.