|
|
|
|
|
by richdougherty
1445 days ago
|
|
It's probably a good default because it's more consistent with how NULL equality is handled in SQL generally. From the article: > In Postgres 14 and prior, unique constraints treated NULL values as not equal to other NULL values. ... > This is consistent with the SQL Standard handling of NULL in general, where NULL is unknown. It is impossible to determine if one unknown is equal to another unknown. Because NULL values are of unknown equality to one another, they do not violate UNIQUE constraints. |
|
The safest implementation would assume that they do violate the constraint, rather than the current behavior assuming they don’t.
In practice I don’t think I’ve ever added a unique index on a nullable column where null might imply unknown. I have used it in cases where null meant “none”.