⚠️ This post links to an external website. ⚠️
Unique indexes can not be created in some cases because a value is duplicated by e.g. soft-deleted rows. By excluding those rows from an index, the uniqueness constraint can be properly set up.
Unique indexes are used to ensure that some values or combinations of values are unique. However, they only work when the uniqueness constraint should be enforced on all table rows because it can not be limited to ignore e.g. soft-deleted ones. But with partial indexes, supported by PostgreSQL, this is possible because a WHERE condition can control the included rows of the index. With MySQL, the behaviour to exclude soft-deleted rows in the uniqueness constraint needs to be emulated.
continue reading on sqlfordevs.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.