Insert – How to Use ‘OR IGNORE’ in SQLite3 Without Leaving Empty Primary Key IDs

insertsqlite

I use 'INSERT OR IGNORE INTO' in my main table which works fine but leaves empty primary key IDs when records are ignored.
This leads to big jumps in my primary key numbering because I re-scan part of the same input data every time.
Can I avoid this and re-set the ID to the last used value before next call?

thanks

Best Answer

Apparently, leaving out the autoincrement from the key definition does the job. The key still autoincrements itself but not when IGNORE is triggered. I found this solution here: https://stackoverflow.com/questions/47120708/sqlite-autoincrement-and-insert-or-ignore-will-produce-unused-autoincrement-key