0

Is there an exception in my pymysql insert statement below that I can use here to pass on looping if the value already exists?

My code looks like:

   try:
       with db.cursor() as cursor:
           sqltld = "INSERT INTO `table`(`colname`) VALUES (%s)"
           cursor.execute(sqltld, (self.url))
           db.commit()
    except:
       print("error INSERTing url")
       db.rollback()

Mysql is already enforcing unique on the column colname

Thanks

Jshee
  • 2,620
  • 6
  • 44
  • 60
  • You might want to try [“INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”](http://stackoverflow.com/questions/548541/insert-ignore-vs-insert-on-duplicate-key-update) – Solarflare Feb 07 '17 at 21:18
  • I meant via an elif, pymysql, exception e.g. `pymysql.exceptions.IntegrityError` – Jshee Feb 07 '17 at 21:39

0 Answers0