# SQLite ON CONFLICT query

**URL:** <https://forum.inductiveautomation.com/t/sqlite-on-conflict-query/97013>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting, database\
**Created:** [October 9, 2024, 11:07am UTC](https://forum.inductiveautomation.com/t/sqlite-on-conflict-query/97013 "2024-10-09T11:07:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 9, 2024, 12:06pm UTC](https://forum.inductiveautomation.com/t/sqlite-on-conflict-query/97013/2 "2024-10-09T12:06:09Z")

</div>

Why not `try` your insert, `catch` the error if there is one since you have a unique constraint and do your update in there? You can follow this logic of this post

> [@Insert into database only if the entry doesn't exist](https://forum.inductiveautomation.com/t/insert-into-database-only-if-the-entry-doesnt-exist/35122/2):
>
> There are two ways to do this - check for a duplicate manually with python before inserting, and if there’s a problem show the screen Make UNIQUE INDEX definitions on your table in the database, and then just try/except inserting into it. Personally I like to leave data integrity to the database where appropriate, and ensuring UNIQUE-ness is one of those times in my opinion. I use this method for a MySQL DB and it looks like this in practice. My personal solution would be to make your n…

---

_[View the full topic](https://forum.inductiveautomation.com/t/sqlite-on-conflict-query/97013)._
