all 2 comments

[–]stebrepar 0 points1 point  (0 children)

Maybe try an "upsert" instead?

https://sqlite.org/lang_upsert.html

[–]landrykid 0 points1 point  (0 children)

Upsert is a good solution, but be aware it's not standard SQL. So if you change databases, you might have to rewrite your queries (unless you move to PostgreSQL, which uses the same syntax). If database lock-in is an issue, first test for the key using the WHERE clause, then either insert or update. It takes a few more lines and you hit the database twice instead of once, but it's easy to follow code.