0

I am new to php and sql, but learning fast. I'm trying to understand the behavior of the db when importing data files using phpMyAdmin. Here is what I'm currently doing, and I'd like to know if I'm taking the best (and only) approach, or should be handling it differently.

1) I export a CVS file from one source, which includes dates and (comma separated) numbers, both in string format (which I need to convert to 'date' and 'int' format).

2) After I import the file into the db, I then add more columns to the end of the table, which I use to convert string to date, and string to integer.

My issues start at this point

3) The next time I import data from the same source, the number of columns don't match up, so I get an error. I had hoped that since new columns are on the end, then the import would just ignore any lack of data, but no. To get around this, I have been manually adding the same # of commas, to match the # of new columns, to each row in the new data file. This seems like a ridiculous approach. Is it possible to import data linearly, or have it ignore importing values for certain columns?

4) Then the new data includes both NEW records and UPDATES to existing records. So it is possible to have the import do both (a) add the new records, while (b) update records with matching primary key?? Otherwise, I find myself deleting the entire db, and importing the new one (which has other nuisances).

Dharman
  • 21,838
  • 18
  • 57
  • 107
noy-hadar
  • 169
  • 1
  • 12
  • Maybe http://stackoverflow.com/questions/4205181/insert-to-table-or-update-if-exists-mysql is giving you a starting point. – frlan Jul 12 '14 at 15:48
  • @frlan that looks like it's for individual records. Does that also apply when importing an entire data file? – noy-hadar Jul 12 '14 at 16:12

0 Answers0