home ~ projects ~ socials

Insert Or Ignore In SQLite

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