Unique constraint on only some of the rows - Mailing list pgsql-novice

From A B
Subject Unique constraint on only some of the rows
Date
Msg-id AANLkTikwhy6ZefkbjfrDYC-2yz9wMVHWsPAXvvO=RRKb@mail.gmail.com
Whole thread Raw
Responses Re: Unique constraint on only some of the rows  (Thomas Kellerer <spam_eater@gmx.net>)
List pgsql-novice
Hello there!

If I want to create a table

create table users (
  id integer
  name varchar(8)
  enabled boolean
);

and a constraint  unique(id,name) but the unique constraint should
only be used for the enabled users, how can I do that?

The only way I can think of is to use null values when a user is not
enabled and use the constraint  unique(id,name,enable).

Are there other ways of doing this?

pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Re: Select and update with limit and locking
Next
From: Thomas Kellerer
Date:
Subject: Re: Unique constraint on only some of the rows