home ~ socials ~ projects ~ rss

Insert Or Ignore In SQLite

July 2015
CREATE TABLE example_table(example_item TEXT UNIQUE);

Then do this:

INSERT OR IGNORE 
INTO example_table(example_item) 
VALUES("alfa bravo");

Note that with this approach an AUTOINCREMENT counter increases even if a row isn't inserted. If that bugs you, you can either not use AUTOINCREMENT (e.g. use the generic ROWID) or use a different approach.

end of line

References

Share link:
https://www.alanwsmith.com/en/01/9t/md/42/?insert-or-ignore-in-sqlite