Ecto insert_all handle constraint

I have a bulk insert with insert_all. The destination table has an excluding constraint. At the end of unsuccessful insert operation I have a Postgrex.Error in my rescue func, Is there any way to adopt this error into something more convenient like changeset error?
The option to make Repo,transaction and insert using

Enum.map(changesets, fn cs -> 
 repo.insert(cs)
end

is not good I think

You can try using the exclusion_constraint:

https://hexdocs.pm/ecto/Ecto.Changeset.html#exclusion_constraint/3

Best regards,

1 Like