Replies: 1 comment 6 replies
-
|
For something like this, you can use you can try an https://piccolo-orm.readthedocs.io/en/latest/piccolo/query_clauses/on_conflict.html#do-update >>> await Items.insert(
... Items(**item_dict)
... ).on_conflict(
... action="DO UPDATE",
... target=[Items.unique_id]
... )So if an item already exists with that For it to work, the In the future we might support the Postgres |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Basically, I have a call where I'm getting tens or possibly hundreds of items that I need to sync into the db (that is, if an item exists, get and update it, otherwise create it). The table has a primary key which is a serial column, but since incoming items don't have that id, there is also a unique composite index that is used to check whether an item exists. So to avoid long processing times, I was planning to do something like:
Is this safe to do? Can there be issues with the serial id for the table? Or for example if duplicated items exist in the input? In the latter case, my expectation would be that if the item did not exist in the db, one would be inserted and the other would be an update of the previously inserted one (I don't mind which one is what, as long as the result is consistent), or if it was already present, then both would be updates (again, order doesn't matter, as long as the result is consistent).
I'm using postgresql as the backing DB.
Beta Was this translation helpful? Give feedback.
All reactions