I want to import CSV files into MySQL 5.7 and would like to load NULL values.
I have read MySQL load NULL values from CSV data
If I use the same sample table and data it works fine. If I however try to import the following data:
1,2,3
1,2,3,4,
1,2,3,4,5
Then the output is: Error Code: 1366. Incorrect integer value: '' for column 'five' at row 2
Table creation script:
create table moo(
one int not null,
two int not null,
three int null,
four int null,
five int null);
I am using the nullif expression for the nullable columns:
LOAD DATA INFILE '/test-moo.txt' INTO TABLE moo
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
(one, two, @vthree, @vfour, @vfive)
SET three = nullif(@vthree,''),
four = nullif(@vfour,''),
five =nullif(@vfive,'');
Is this a bug or am I missing something? It only seems to go wrong with the last column.