I am currently using LOAD DATA LOCAL INFILE
successfully, and typically with REPLACE
. However, I am now trying to use the same command to load a CSV file into a table but only replace specific columns.
For example, table currently looks like:
ID date num1 num2
01 1/1/2017 100 200
01 1/2/2017 101 201
01 1/3/2017 102 202
where ID
and date
are the primary keys.
I have a similar CSV, but one that only has ID, date, num1
as columns. I want to load that new CSV into the table, but maintain whatever is in num2
.
My current code per this post:
LOAD DATA LOCAL INFILE mycsv.csv
REPLACE INTO TABLE mytable
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(ID, date, num1)
Again, my code works flawlessly when I'm replacing all the columns, but when I try to replace only select columns, it fills the other columns with NULL values. The similar posts (like the one I referenced) haven't helped.
I don't know if this is python specific issue, but I'm using MySQLdb
to connect to the database and I'm familiar with the local_infile
parameter and that's all working well. MySQL version 5.6.33.