Deferred constraints

140 views
Skip to first unread message

Sebastian Kosch

unread,
Jun 25, 2016, 1:38:15 PM6/25/16
to elixir-ecto
Hi,

I'm wondering if (and if yes, how) it is possible to use Ecto to mark constraints as DEFERRED (https://www.postgresql.org/docs/9.1/static/sql-set-constraints.html).

I'm in a situation where I'm swapping out two values between two rows. These values happen to be in a column that has a unique constraint on it, and so I get an error as soon as I fire off the first update.
Since I'm performing both updates within a transaction, and since it's a clean swap, the overall result is perfectly kosher, but Ecto doesn't understand that.

Do changesets know anything about the transactions they're in? Is this doable somehow, without any intermediate steps? Is there another elegant approach that I haven't considered?

Thanks!

Sebastian

José Valim

unread,
Jun 25, 2016, 2:05:42 PM6/25/16
to elixi...@googlegroups.com
You can use Ecto.Adapters.SQL.query/3 to issue a query to the database, inside the transaction, that will set the deferred mode.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/d15c4f3a-f82b-4c18-94cd-14b9c3d68ae1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Kosch

unread,
Jun 25, 2016, 2:09:07 PM6/25/16
to elixi...@googlegroups.com
Ahh, perfect! Thanks José, much appreciated!
You received this message because you are subscribed to a topic in the Google Groups "elixir-ecto" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-ecto/vWDoZcRWrqo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAGnRm4LOQx-NVfVnnyxVpooUbL72Gp79MUC2FA6B9WuUxQdORA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages