0

Question is almost similar to Check if records exists in a Postgres table but in my case, i don't have any unique column. Currently i'm adding records from csv to mysql using php with this query:

"LOAD DATA LOCAL INFILE '".$file."' INTO TABLE $table FIELDS TERMINATED BY '$fieldSeperator' ";

where $file is csv file, $table is name of table and $fieldSeperator is , or \t

But the above query can only add new record without comapring to previous. How to check for rows if they dont exist then add new else no change?

Community
  • 1
  • 1
Raza Ahmed
  • 2,661
  • 2
  • 35
  • 46
  • you will have to open the file and loop to process it, you wont be able to use LOAD DATA if you need row by row processing –  Mar 30 '14 at 19:48
  • @Dagon is there any solution like http://stackoverflow.com/a/12756520/2037323 ? – Raza Ahmed Mar 30 '14 at 19:49
  • from what i understand of your question, no. –  Mar 30 '14 at 19:49
  • I asked @erwin-brandstetter about that but was not able to understand that, he replied: Join on enough columns to make it unique. All columns if you have to. The USING or the NATURAL clause would come in handy for that. Normally, every table should have a primary key, though – Raza Ahmed Mar 30 '14 at 19:52
  • 1
    or may be to create a temp table and then compare both tables and then add? – Raza Ahmed Mar 30 '14 at 19:54
  • how do you determine, what should be added ? –  Mar 30 '14 at 19:54
  • let first records added from csv and after that, i change/add a record in csv, now when i load that csv, it should only add 1 new record to that table – Raza Ahmed Mar 30 '14 at 20:00

0 Answers0