Set as NULL when importing csv with missing values.

Jason210's profile image Jason210 posted 4 years ago in General Permalink

Hi

I am trying to import a CSV file that has a few missing fields. These are represented by ,,

I have checked the CSV file and it looks OK.

When I import, it works fine except that any missing values that are in numerical columns are set to the number 0, which is bad. I need them set to NULL. I have set up the table to use NULL as default. One of the columns in question is created with this command:

GAMING_SCORE FLOAT(3,1) UNSIGNED DEFAULT NULL

Can anyone advise me on how to solve this please?

Jason

ansgar's profile image ansgar posted 4 years ago Permalink

You could make an UPDATE after the import:

UPDATE gaming_score SET colX=NULL WHERE colX=''
Jason210's profile image Jason210 posted 4 years ago Permalink

Thank you. I eventually found some information about it on Stack Exchange and ended up pre-processing the CSV with Find & Replace, putting an \N in the missing fields. I like the update suggestion better.

Please login to leave a reply, or register at first.