Question

Working here on bulk insert, which skips 2 records. Explanation below:

My table (works fine, Auto-incrementing Job_Id):



create table avjobs ( Job_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, 
Job_Name varchar(255), Job_Seq varchar(255), Job_Date varchar(255), 
Start_Time time, End_Time time, Runtime time, Status varchar(255) );

Here is my csv file:

JOB1A|0029|20140506|14:01:05|15:00:01|0:59:45|FINISHED
JOB2B|0030|20140506|15:01:05|16:00:01|0:59:55|INITIATED

Here is the BULK INSERT that I am using:

LOAD DATA LOCAL INFILE '/tmp/jobs.csv' INTO TABLE avjobs FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
Query OK, 3 rows affected, 9 warnings (0.00 sec)

Here is output for select:

mysql> select * from avjobs;
+--------+----------+----------+----------+------------+----------+----------+--------+
| Job_Id | Job_Name | Job_Seq  | Job_Date | Start_Time | End_Time | Runtime  | Status |
+--------+----------+----------+----------+------------+----------+----------+--------+
|      1 | 0029     | 20140506 | 14:01:05 | 15:00:01   | 00:23:55 | 00:00:00 | NULL   |
|      2 | 0030     | 20140506 | 15:01:05 | 16:00:01   | 00:59:55 | 00:00:00 | NULL   |
+--------+----------+----------+----------+------------+----------+----------+--------+

The Bulk insert skips, somehow, the job name as well as status.

Can you please advise what is wrong in syntax?

Was it helpful?

Solution

You must specify your columns:

LOAD DATA LOCAL INFILE '/tmp/jobs.csv' 
INTO TABLE avjobs (Job_Name, Job_Seq, Job_Date, Start_Time, End_Time, Runtime, Status)    
FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';

because your import file doesn't contain your Job_ID, see manual

LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata; By default, when no column list is provided at the end of the LOAD DATA INFILE statement, input lines are expected to contain a field for each table column. If you want to load only some of a table's columns, specify a column list:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top