Partial indexes are useful for enforcing rules that only apply conditionally

Partial indexes are useful for enforcing rules that only apply conditionally

⚡️ Database Tip

Sometimes you want to make columns unique but you can't because e.g. there are still soft-deleted rows in the table witht the same value. By only including relevant rows (partial index) you can still enforce uniqueness, and you can even simulate it for MySQL!

We're writing a book, you can get it for free here.