Ecto has nice support for contraints, which I’ve written about and contributed to.
But when you violate multiple constraints, PostgreSQL only tells you about them one at a time. This means that a user would have to fill out a form, submit, fix an error, resubmit, fix another error… etc. To avoid this, we have to check things like NOT NULL with validations in addition to the underlying database constraint.
If PostgreSQL could tell us all the violated constraints at once, that would simplify things, wouldn’t it?
If you agree, maybe go upvote this item on the PostgreSQL user voice? https://postgresql.uservoice.com/forums/21853-general/suggestions/308845-give-names-of-violated-constraint
So, that PostgreSQL issue was closed with the following message:
This was implemented in 9.3. See PG_DIAG_CONSTRAINT_NAME.
I found that on this page, but:
- it’s not clear to me if using
PG_DIAG_CONSTRAINT_NAME would return all violated constraints or just the first one, like I see in
- I know beans about programming C, so I don’t know how to test this. I don’t really even know whether or where
libpq figures into the Ecto stack.
My understanding is that we have something like this:
│ Ecto │
│ Postgrex │
│ connects on
│ port 5432 (or other)
│ PostgreSQL Server │
libpq involved here somewhere? If so, is there any way to try to get it to query this information?
@ericmj I’d love to help us make use of this, but I need to get a clue about the stack first.
Postgrex does not use
libpq - the PostgreSQL protocol is implemented natively in Elixir.
libpq and postgrex follow the same constraints since they speak the same protocol, the only difference is that libpq uses text serialisition and postgrex uses the binary format, but that should not matter in this case.
Unfortunately I don’t think the issue you linked solves what you want. Ecto already uses the feature in the issue to link errors with changeset validations. The issue doesn’t seem to have a solution for multiple errors reported from Postgres.