Specify behavior for nulls in a unique index
Postgres 15 gave us the ability to specify how we want null values to be treated when dealing with unique indexes.
By default, nulls are considered unique values in Postgres:
This default behavior can also be explicitly set using the nulls distinct
clause:
To change the default behavior and prevent nulls from being considered unique values, you can use the nulls not distinct
clause:
See this change in the Postgres 15 release notes
Tweet