0

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?

1
  • have you tried it? for that matter, are you sure that sending 500 queries in one string actually improves performance? why not just insert 500 rows with one query? does INSERT IGNORE do what you want? Commented Jul 9, 2014 at 22:01

1 Answer 1

1

For anyone that cares, the ON DUPLICATE KEY UPDATE SQL command was what I ended up using.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.