Load data infile ignore first field
Posted: Thu Feb 02, 2012 5:34 pm
As part of a project I'm working on I have to store quite a lot of data locally on a .txt file and then insert it into a MySQL database.
I'll most likely be using LOAD DATA INFILE for this.
So, to the point: my first field is ID. I do not want to insert anything into the ID field. Is it possible to tell SQL to ignore the first field? What I do now is start my string with a field delimiter. Like this:
My SQL looks like this:
I'll most likely be using LOAD DATA INFILE for this.
So, to the point: my first field is ID. I do not want to insert anything into the ID field. Is it possible to tell SQL to ignore the first field? What I do now is start my string with a field delimiter. Like this:
,This,is,text,\n ,This,text,is,\n ,text,is,This,\n ,is,This,text,\nbut I will probably forget to add the commas to the start of each line when I have to sit down and write every line by hand(400+lines) and I'm quite certain that my brain will turn into mush and / or something materialistic will break if I start seeing MySQL errors.
My SQL looks like this:
LOAD DATA INFILE 'C:/Path/To/File/file.txt' INTO TABLE mytable FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';Thanks in advance