0

I have a UNIQUE constraint for columns username + user_status, such that we never allow two users that have the same name and status. However I wish this to apply only to the case where the status field is 'ACTIVE' but allow any number of records with the same username and status of 'INACTIVE'. Is this possible?

1
  • Which implies that you could never set a user to ACTIVE if a user with the same name is ACTIVE. Commented Sep 26, 2020 at 11:56

1 Answer 1

5

You can create a filtered unique index:

create unique index on the_table (username)
where user_status = 'ACTIVE';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.