[ Python Ignore MySQL IntegrityError when trying to add duplicate entry with a Primary key ]
So I have a string in Python that contains like 500 SQL INSERT queries, separated by ;
. This is purely for performance reasons, otherwise I would execute individual queries and I wouldn't have this problem.
When I run my SQL query, Python throws: IntegrityError: (1062, "Duplicate entry 'http://domain.com' for key 'PRIMARY'")
Lets say on the first query of 500, the error is thrown. How can I make sure those other 499 queries are executed on my database?
If I used a try and except, sure the exception wouldn't be raised, but the rest of my statement wouldn't be executed. Or would it, since Python sends it all in 1 big combined string to MySQL?
Any ideas?
Answer 1
For anyone that cares, the ON DUPLICATE KEY UPDATE
SQL command was what I ended up using.