'Partial unique index in Postgres to ensure existence of a row that satisfies the constraint?
I have a users table, a teams table and a users_teams table.
I am looking for a way in postgres to do the following:
I want to ensure that a user always has a default team, a record with is_default true in the users_teams table.
I know I can use partial unique index for making sure a user does not have more than 1 default team, so I am wondering if something of the same effect is possible.
Thank you
Solution 1:[1]
Add a foreign key that is NOT NULL to the users table that points to the default team of the user.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Laurenz Albe |
