When using LOAD DATA INFILE, is there a way to either flag a duplicate row, or dump any/all duplicates into a separate table?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- sqlyog export query result as csv
From the LOAD DATE INFILE documentation:
Effectively, there's no way to redirect the duplicate records to a different table. You'd have to load them all in, and then create another table to hold the non-duplicated records.
It looks as if there actually is something you can do when it comes to duplicate rows for LOAD DATA calls. However, the approach that I've found isn't perfect: it acts more as a log for all deletes on a table, instead of just for LOAD DATA calls. Here's my approach:
Table test:
Table test_log:
Trigger del_chk:
Test import (
/home/user/test.csv
):Query:
Running the above query will result in
1,asdf
,1,tyui
, and2,jkl
being added to the log table. Based on a timestamp, it could be possible to associate the rows with a particularLOAD DATA
statement.