Support NULLS NOT DISTINCT Postgres 15+ clause

By default, NULL values are treated as distinct entries. Specifying NULLS NOT DISTINCT on unique indexes / constraints on Postgres 15+ will cause NULL to be treated as not distinct, or in other words, equivalently.

References

Could Django support that clause?

1 Like

There’s an easy workaround at the moment. You can create your own custom migration to alter a table to include that option.

However, since this isn’t currently supported even by all versions of PostgreSQL that are supported by Django, I’m not sure it would be appropriate to add support for this at this time, even in django.contrib.postgres.

From my understanding this feature is part of the SQL:2023 standard so adding support for it in UniqueConstraint even if it’s only supported by Postgres 15+ at the moment seems like a feature that would be accepted.

1 Like

@alanoe I recently submitted a PR to add support for it. Reviews welcome!