views:

167

answers:

2

First of, a simplified version: I am wondering if I can create a trigger to activate during INSERT (it's actually LOAD DATA INFILE) and NOT enter records for an RMA already in my table?

I have a table that has no records that are unique. Some may be legitimate duplicates but there is one field that I can use to know if the data has been entered or not. For instance

RMA     Op     Days
---------------------
213   Repair   0.10
213    Test    0.20
213   Repair   0.10

So I could do an index on the three columns together but as you see it's possible for an RMA to be in a step for the same amount of time twice so it's possible to have duplicate records. Basically, I want the Trigger to say if NEW.rma is in the table already, skip to the next row.

I found out there are ways to make a Trigger halt the Insert so I guess my question now is, how can I skip an insert and continue with the rest during a LOAD DATA INFILE call?

A: 

Could you set up a compound key derived from the RMA and the OP? That would cause duplicate entries to show up as errors.

Satanicpuppy
Duplicate entries aren't errors, that's my issue. The data seen in the post is what a valid entry would look like. What I don't want though is for those three rows to be entered a second time.I have an automated report running Excel file that queries reports from Oracle and then inserts the data into my database. It runs from the first of the current month to the current date and runs LOAD DATA INFILE. With my other reports it works fine because LOAD DATA INFILE will skip over the duplicates but here there is no way for LOAD DATA INFILE to know so I have to somehow catch it.
Geoff
I would just always run from the time I ran the last report but there are times when I get an Error from the Oracle reporting query so I'm not always sure of the exact time it ran last and it's just easier to load all data Month to date.
Geoff
A: 

The simplest way I can think of is to load into a new table, then delete the old and rename the new. LOCK TABLES should be able to isolate that switch at the end.

Alternatively, if you are sure about the order in which rows appear in the insert file - i.e., if it is guaranteed that the file has the old rows followed by the new rows - then you can COUNT(*) first, then skip that number of rows when loading.

Andrew Duffy