[MDEV-11235] LOAD DATA does not honor strict modes Created: 2016-11-04  Updated: 2016-11-13  Resolved: 2016-11-13

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.2.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Nirbhay Choubey (Inactive) Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: need_feedback

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

 Description   

Zero date could be inserted using LOAD DATA even under 'NO_ZERO_DATE' mode.

MariaDB [test]> set sql_mode='';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create table t1(c1 date default '0000-00-00');
Query OK, 0 rows affected (0.08 sec)
 
MariaDB [test]> \! echo "" > /tmp/data
 
MariaDB [test]> insert into t1 values ();
Query OK, 1 row affected (0.00 sec)
 
MariaDB [test]> load data local infile '/tmp/data' into table t1;
Query OK, 1 row affected, 1 warning (0.01 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 1
 
MariaDB [test]> select * from t1;
+------------+
| c1         |
+------------+
| 0000-00-00 |
| 0000-00-00 |
+------------+
2 rows in set (0.01 sec)
 
MariaDB [test]> set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE';
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> insert into t1 values ();
ERROR 1978 (22007): Incorrect default value '0000-00-00' for column 'c1'
 
MariaDB [test]> load data local infile '/tmp/data' into table t1;
Query OK, 1 row affected, 1 warning (0.04 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 1
 
MariaDB [test]> show warnings;
+---------+------+-----------------------------------------+
| Level   | Code | Message                                 |
+---------+------+-----------------------------------------+
| Warning | 1265 | Data truncated for column 'c1' at row 1 |
+---------+------+-----------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [test]> select * from t1;
+------------+
| c1         |
+------------+
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
+------------+
3 rows in set (0.00 sec)
 
MariaDB [test]> show create table t1;
+-------+---------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                |
+-------+---------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `c1` date DEFAULT '0000-00-00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)



 Comments   
Comment by Elena Stepanova [ 2016-11-04 ]

This section talks about duplicate keys, but I think the same logic applies:
http://dev.mysql.com/doc/refman/5.7/en/load-data.html

If you specify IGNORE, rows that duplicate an existing row on a unique key value are discarded. For more information, see Comparison of the IGNORE Keyword and Strict SQL Mode.

If you do not specify either option, the behavior depends on whether the LOCAL keyword is specified. Without LOCAL, an error occurs when a duplicate key value is found, and the rest of the text file is ignored. With LOCAL, the default behavior is the same as if IGNORE is specified; this is because the server has no way to stop transmission of the file in the middle of the operation.

Comment by Elena Stepanova [ 2016-11-12 ]

nirbhay_c,
I am inclined to close it as not a bug, unless you disagree with the above.

Comment by Nirbhay Choubey (Inactive) [ 2016-11-13 ]

elenst I agree with the documented behavior. Thanks for pointing.

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