How to change particular column entries in a mysql table when uploading data from csv file?
Posted
by understack
on Stack Overflow
See other posts from Stack Overflow
or by understack
Published on 2010-05-09T19:13:10Z
Indexed on
2010/05/09
19:18 UTC
Read the original article
Hit count: 130
I upload data into a mysql table from csv file in a standard way like this:
TRUNCATE TABLE table_name;
load data local infile '/path/to/file/file_name.csv' into table table_name
fields terminated by ','
enclosed by '"'
lines terminated by '\r\n'
(id, name, type, deleted);
All 'deleted' column entries in csv file has either 'current' or 'deleted' value.
Question: When csv data is being loaded into table, I want to put current date in table for all those corresponding 'deleted' entries in csv file. And null for 'current' entries. How can I do this?
Example: csv file:
id_1, name_1, type_1, current
id_2, name_1, type_2, deleted
id_3, name_3, type_3, current
Table after loading this data should look like this:
id_1, name_1, type_1, null
id_2, name_1, type_2, 2010-05-10
id_3, name_3, type_3, null
Edit Probably, I could run another separate query after loading csv file. Wondering if it could be done in same query?
© Stack Overflow or respective owner