sql - LOAD DATA INFILE (*.csv) - ignore empty cells -


i'm import large (500 mb) *.csv file mysql database.

i'm far that:

load data infile '<file>'     replace     table <table-name>     fields         terminated ';'         optionally enclosed '"'     ignore 1 lines ( #header         <column-name1>,         <column-name2>,         ...     ); 

i have problem 1 of coluns (it's data type int) - error message:

error code: 1366 incorrect integer value: ' ' column @ row

i looked @ line in *.csv-file. cell causes error has whitespace inside (like this: ...; ;...).

how can tell sql ignore whitespaces in column?

as *.csv-file big , have import bigger ones afterwards, i'd avoid editing *.csv-file; i'm looking sql-solution.

thank you!

[edit] solution is:

load data infile '<file>'     replace     table <table-name>     fields         terminated ';'         optionally enclosed '"'     ignore 1 lines ( #header         <column-name1>,         <column-name2>,         @var1 #the variable causes problem         ...     )     set <column-name-of-problematic-column> = case         when @var1 = ' ' null         else @var1     end ; 

add set column so:

load data infile 'file.txt'   table t1   (column1, @var1)   set column2 = @var1/100; 

you need replace @var1/100 expression handles 'space' , convert -infinity or 0 or 42... not sure..


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -