Upsert with ON CONFLICT DO NOTHING

Is it possible to configure an upsert to do ON CONFLICT DO NOTHING?
Solution:
Yeah that would likely do it 🙂
Jump to solution
6 Replies
Jesse Williams
Jesse WilliamsOP•3mo ago
I just found upsert_condition - am I understanding correctly that I could simply do expr(false) for that which would always do nothing...?
ZachDaniel
ZachDaniel•3mo ago
Yep We could probably special case that to DO_NOTHING also Feel free to open an issue w/ that
Jesse Williams
Jesse WilliamsOP•3mo ago
Hmm, 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
ZachDaniel
ZachDaniel•3mo ago
Ah right try adding a filter to the changeset instead Ash.Changeset.filter Might be the same thing
Jesse Williams
Jesse WilliamsOP•3mo ago
Yeah 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
ZachDaniel
ZachDaniel•3mo ago
Yeah that would likely do it 🙂

Did you find this page helpful?