I'm importing a CSV into a MySQL table with LOAD DATA INFILE. One of the table's fields stores zip code data, which I've defined in the table structure contributor_zipcode INT.
In the CSV, this field is sometimes empty. When I execute the LOAD query, MySQL will throw a warning like:
Incorrect integer value: '' for column 'contributor_zipcode' at row 180
I've tried redefining the field as contributor_zipcode INT DEFAULT '0', which creates the same warning, and contributor_zipcode INT DEFAULT NULL, which MySQL won't allow. Any advice?
解决方案
The empty values are being interpreted as the empty string (''), not NULL, so the default value is not being used.
If you want to explicitly control the handling of these empty strings, the best thing to do is to load them into a user variable, and then set the column