While most backends default to implicit `NULLS DISTINCT` some backends
don't, most notably SQL Server (cff59bedc23fd4d53557f677ddc42402b56963d0).
I suggest we add a `nulls_distinct: Optional[bool]=None` option to
`UniqueConstraint` so it preserves it's ''default to backend treatment of
nulls'' behaviour while allowing it to be set explicitly on backends that
support it.
- [https://modern-sql.com/caniuse/unique-nulls-not-distinct Article on the
subject]
- [https://modern-sql.com/caniuse/F292 SQL:F292]
- [https://forum.djangoproject.com/t/support-nulls-not-distinct-
postgres-15-clause/21973/3 Recent thread on the subject in the forums]
--
Ticket URL: <https://code.djangoproject.com/ticket/34701>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Simon Charette):
Replying to [ticket:34701 Simon Charette]:
> PostgresSQL 15 is one of the first databases to implement the F292 SQL
feature present in the 2023 standard that allows to specify whether or not
null values should be considered as distinct in unique constraints.
>
> While most backends default to implicit `NULLS DISTINCT` some backends
don't, most notably SQL Server (cff59bedc23fd4d53557f677ddc42402b56963d0).
>
> I suggest we add a `nulls_distinct:Optional[bool]=None` option to
`UniqueConstraint` so it preserves it's ''default to backend treatment of
nulls'' behaviour while allowing it to be set explicitly on backends that
support it.
>
> - [https://modern-sql.com/caniuse/unique-nulls-not-distinct Article on
the subject]
> - [https://modern-sql.com/caniuse/F292 SQL:F292]
> - [https://forum.djangoproject.com/t/support-nulls-not-distinct-
postgres-15-clause/21973/3 Recent thread on the subject in the forums]
--
Ticket URL: <https://code.djangoproject.com/ticket/34701#comment:1>
Old description:
> PostgresSQL 15 is one of the first databases to implement the F292 SQL
> feature present in the 2023 standard that allows to specify whether or
> not null values should be considered as distinct in unique constraints.
>
> While most backends default to implicit `NULLS DISTINCT` some backends
> don't, most notably SQL Server
> (cff59bedc23fd4d53557f677ddc42402b56963d0).
>
> I suggest we add a `nulls_distinct: Optional[bool]=None` option to
> `UniqueConstraint` so it preserves it's ''default to backend treatment of
> nulls'' behaviour while allowing it to be set explicitly on backends that
> support it.
>
> - [https://modern-sql.com/caniuse/unique-nulls-not-distinct Article on
> the subject]
> - [https://modern-sql.com/caniuse/F292 SQL:F292]
> - [https://forum.djangoproject.com/t/support-nulls-not-distinct-
> postgres-15-clause/21973/3 Recent thread on the subject in the forums]
New description:
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/34701#comment:2>
* owner: nobody => Simon Charette
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34701#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34701#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1" 595a2ab]:
{{{
#!CommitTicketReference repository=""
revision="595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1"
Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34701#comment:5>