Import only selected columns CSV

[expired user #7481]'s profile image [expired user #7481] posted 11 years ago in Import/Export Permalink
I want to only update one column in a table.
The table has an index column.
So my data looks likes this:
123, 8
125, 4
222, 6
333, 1

The table already contains rows with the values 123, 125, etc
Table columns are:
Index, col2, col3 ColX

I want to update ColX. I have tried with dummy columns in my CSV for col2 & col3 but no good because it complains about no default vlaue for col2.

Import CSV needs some more options. How can I write an SQL query to do this? I need access to the CSV data. I guess I could import into a dummy table then write some SQL to do the update. Not sure what this SQL qould look like.

Thanks DG
jfalch's profile image jfalch posted 11 years ago Permalink
this is not possible with import csv, options or not. if you want to update only one column, you have to generate an sql file with a line like
UPDATE table SET colX=valX WHERE keyFieldOfRecord=keyvalX;
for each record to be updated.
[expired user #7481]'s profile image [expired user #7481] posted 11 years ago Permalink
In the Import CSV window on HeidiSQL there is a check box against each column name. I would have thought this was for selecting which fields were to be updated, but it doesn't work like that. What is the purpose of these check boxes anbd exactly how do they work?
Can't Heidi generate the SQL statement you gave for me?
jfalch's profile image jfalch posted 11 years ago Permalink
the check boxes are used when you have a .csv import record that contains more fields than the table imported to; they select which of the fields are used for import.

heidisql currently cannot generate the UPDATE statements required; you would have to use/write a program, processing your input file, to do this. AWK or PERL would be good candidates for languages to write this program in.

Please login to leave a reply, or register at first.