tags:

views:

25

answers:

1

Is there an easy way to return something to your code if a duplicate insert is attempted?

I want to do something like this (Obviously doesn't work because (ON DUPLICATE KEY INDEX UPDATE)-

query = "INSERT INTO quotes(symbol, date, open, high, low, close, volume, adj)"
query += "VALUES ('" + symbol + "', '" + Date + "','" + Open + "','" + High + "','" +  Low + "','" + Close + "','" + Volume + "','" + Adj +"') ON DUPLICATE KEY INDEX SELECT (2)"

Maybe there is something with INSERT IGNORE INTO?

Basically I need to populate a database with millions of entries but it usually gets cut off in the middle, and this would speed it up as I could determine how far it made it last time in the code

Thanks for any help you can provide

A: 

Catch the exception raised by the DB-API adapter.

Ignacio Vazquez-Abrams
thanks, I was looking for a way to do it in SQL but as I couldn't find anything and you suggest this, it seems to be the only option
b8b8j
Just got back to working on it, for anyone else looking the exception is:MySQLdb.IntegrityError
b8b8j