Opened 16 months ago

Closed 16 months ago

Last modified 4 months ago

#34701 closed New feature (fixed)

Add support for NULLS [NOT] DISTINCT to UniqueConstraint

Reported by: Simon Charette Owned by: Simon Charette
Component: Database layer (models, ORM) Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by 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.

Change History (6)

comment:1 by Simon Charette, 16 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 16 months ago

Triage Stage: UnreviewedAccepted

comment:3 by Simon Charette, 16 months ago

Has patch: set
Owner: changed from nobody to Simon Charette

comment:4 by Mariusz Felisiak, 16 months ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 16 months ago

Resolution: fixed
Status: assignedclosed

In 595a2ab:

Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.

comment:6 by Sarah Boyce <42296566+sarahboyce@…>, 4 months ago

In 0e49a8c3:

Refs #34701 -- Moved UniqueConstraint(nulls_distinct) validation tests.

The original tests required the creation of a model that is no longer necessary
and were exercising Model.full_clean(validate_constraints) which has nothing
to do with the nulls_distinct feature.

Note: See TracTickets for help on using tickets.
Back to Top