I'm trying to read a csv file and load the values to a mysql table.
My csv file looks like this:
"1026235","2172","Werdmühlestrasse","4","400","Werdmühlestrasse 4","3","real","BB","261AA01857","3169179","2683137.449","1247708.724","8001","0","Zürich","AA1750","","K","1","Lindenhof","13","1301","Zürichberg","Altstadt","St.Peter u Paul","St.Peter","1026238","562","Fortunagasse","15","1500","Fortunagasse 15","3","real","BB","261AA01852","140709","2683163.645","1247502.811","8001","0","Zürich","AA5297","","K","1","Lindenhof","13","1301","Zürichberg","Altstadt","St.Peter u Paul","St.Peter","1","3","3","29.0","8.539764579706915","47.373115180353350","POINT (2683163.8 1247502.8)"
This is the command I'm trying to run:
LOAD DATA INFILE '/home/coder/project/geoz.adrstzh_adressen_stzh_p.csv'
INTO TABLE mainZuerichAddresses
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(@col1,@dummy,@col3,@col4,@dummy,@col6,@col7,@dummy,@dummy,@col10,@dummy,@dummy,@dummy,@col14,@dummy,@col16,@dummy,@dummy,@dummy,@col20,@col21,@dummy,@col23,@col24,@col25,@col26,@col27,@col28,@col29,@dummy,@dummy,@dummy,@dummy,@col34)
SET objid=@col29,gebaeudeeingangnummer=@col1,adresse=@col6,lokalisationsname=@col3,
hausnummer=@col4,plz=@col14,plz_ortschaft=@col16,stadtkreis=@col20,
gebaeudenummer=@col10,statistisches_quartier=@col21,status=@col7,statistische_zone=@col23,schulkreis=@col24,verwaltungsquartier=@col25,
roem_kath_kirchgemeinde=@col26,ev_ref_kirchgemeinde=@col27,ev_ref_kirchenkreis=@col28,geometry=@col34;
Here I added all the 34 columns from the csv file:
(@col1,@dummy,@col3,@col4,@dummy,@col6,@col7,@dummy,@dummy,@col10,@dummy,@dummy,@dummy,@col14,@dummy,@col16,@dummy,@dummy,@dummy,@col20,@col21,@dummy,@col23,@col24,@col25,@col26,@col27,@col28,@col29,@dummy,@dummy,@dummy,@dummy,@col34)
and here I'm trying to add the data to the table columns I have, which are in a different order than the csv and I don't need all of them, only 18. (Can I even do that, cherry-pick columns from the csv file and mix their order?)
SET objid=@col29,gebaeudeeingangnummer=@col1,adresse=@col6,lokalisationsname=@col3,hausnummer=@col4,plz=@col14,plz_ortschaft=@col16,stadtkreis=@col20,gebaeudenummer=@col10,statistisches_quartier=@col21,status=@col7,statistische_zone=@col23,schulkreis=@col24,verwaltungsquartier=@col25,roem_kath_kirchgemeinde=@col26,ev_ref_kirchgemeinde=@col27,ev_ref_kirchenkreis=@col28,geometry=@col34;
But I'm keep getting this error:
ERROR 1366 (HY000): Incorrect integer value: 'Werdmühlestrasse 4' for column 'plz' at row 1
I read the documentation, but it's not very clear how the mysql should be formatted.:
You must also specify a column list if the order of the fields in the input file differs from the order of the columns in the table. Otherwise, MySQL cannot tell how to match input fields with table columns.
I based my mysql command on this question, but it's quite old.
I also found this question which gave some advice about FIELDS and LINES termination so I played around a bit with that.
I'm not sure if the csv formatting is the problem or the order I'm trying to load the data from the csv into the table colums.
Someone has an idea?