Summary of the issue: With MySQL and SQLite, a failed INSERT OR IGNORE
on a table with AUTOINCREMENT still increases the autoincremented value. This has been discussed here: INSERT IGNORE increases auto increment counter even no record is added?
My issue: a table with 99% failed inserts ends up with huge index numbers, for example record 1500 has the index 165200.
This is impractical, so I am looking for a way to counter this behaviour.
Since INSERT OR IGNORE
is supposedly the same as INSERT ON CONFLICT IGNORE
, I have thought of using INSERT ON CONFLICT FAIL
or INSERT ON CONFLICT ABORT
.
My problem is that I am inserting from a SELECT
this way:
INSERT OR IGNORE INTO t1 (x,y,z,) SELECT * FROM t2
This syntax does not accept ON CONFLICT FAIL
. Neither of those two work:
INSERT ON CONFLICT FAIL INTO t1 (x,y,z,) SELECT * FROM t2
INSERT INTO t1 (x,y,z,) SELECT * FROM t2 ON CONFLICT FAIL
Any thoughts or hints?