Skip to content
Advertisement

How to enforce that there is only one `true` value in a column per names (in an enum) of another column?

I have the following structure with an enum { 'ready', 'set', 'go'} on name:

How can I put a constraint on it so that there will only ever be 3 true‘s (one on ready, one on set, and one on go)?

Advertisement

Answer

You can use filtered unique indexes (or as Postgres calls them “partial indexes”):

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement