Upsert with ON CONFLICT DO NOTHING
Is it possible to configure an upsert to do ON CONFLICT DO NOTHING?
6 Replies
I just found
upsert_condition
- am I understanding correctly that I could simply do expr(false)
for that which would always do nothing...?Yep
We could probably special case that to
DO_NOTHING
also
Feel free to open an issue w/ thatHmm, tinkering with this, it seems that I actually wind up getting a StaleRecord error when trying to upsert something onto a record that fails the condition expression
Ah right try adding a filter to the changeset instead
Ash.Changeset.filter
Might be the same thingYeah looking at source code it looks like that's the same thing (I think). I wonder if you could trigger similar-ish behavior by setting
upsert_fields
to []
. I've kinda moved on here since I realized that using ON CONFLICT DO NOTHING
was not actually the solution I needed so this is more of a hypothetical question at this point.Solution
Yeah that would likely do it 🙂