* owner: nobody => SD-13
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34943#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Alex Vandiver):
It's worth noting that [PostgreSQL's `INSERT`
documentation](https://www.postgresql.org/docs/current/sql-insert.html)
suggests ''against'' `ON CONFLICT ON CONSTRAINT`, preferring the raw list
of expressions:
> It is often preferable to use unique index inference rather than naming
a constraint directly using `ON CONFLICT ON CONSTRAINT constraint_name`.
Inference will continue to work correctly when the underlying index is
replaced by another more or less equivalent index in an overlapping way,
for example when using `CREATE UNIQUE INDEX ... CONCURRENTLY` before
dropping the index being replaced.
That is, naming a specific constraint is in general more brittle, since it
depends on the specific name, rather than naming the ''effect'' of the
constraint.
In our particular use case, we also currently only have a unique index,
not a constraint -- and I'm not sure how well doing that migration would
go. But that's a separate issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/34943#comment:6>
* cc: Simon Charette (added)
Comment:
Makes sense.
I guess that from an application maintenance perspective there are still
benefits in using references to already defined constraint though, think
of urlpattern names, annotations, lookups.
To take back the example above nothing would prevent the ORM from simply
resolving `unique_constraint='unique_profile_stream_topic'` to
`('user_profile_id', 'stream_id', Upper('topic_name'))` and avoid the
database level usage of `ON CONFLICT ON CONSTRAINT` if that's discouraged.
In other words, the ''aliasing'' capabilities could be solely done at the
application level assuming users opt-in into the usage of
`Meta.constraints`. That would also happen to address the issue involved
in dealing with the difference between unique indexes and constraints as
Postgres treat them differently.
--
Ticket URL: <https://code.djangoproject.com/ticket/34943#comment:7>