One option is to simply write the loop manually with an error, instead of using executemany .
Psuedocode:
for row in csvfile: try: cursor.execute('INSERT INTO X (Y) VALUES (%s)' % row[rowdatapoint]) except IntegrityError: pass
It is probably not as efficient as executemany , but it will catch your error without delving into the more complex SQL changes that may be associated with creating a giant INSERT SQL string.
jdotjdot
source share