sql - Mysql Load Data: SET IF for all or given subset of columns? -
got working import code csv files 8-column database here:
load data local infile 'file.csv' table mytable fields terminated ',' optionally enclosed '"' lines terminated '\n' ignore 1 lines (col1, col2, @var3, @var4, col5, col6, col7, col8) set col3 = if(@var3 = '', null, @var3), col4 = if(@var4 = '', null, @var4) ;
it's working fine in changing empty entries null values, but.... there way shorten set part don't have specify condition each , every column? need 7 of 8 columns above, , particular table rather small.
is there way shorten set part
yes, mysql provides shorthand function
nullif()
:col3 = nullif(@var3, '') -- etc
so don't have specify condition each , every column?
sadly not, although should trivial generate desired sql dynamically in application code.
Comments
Post a Comment