Re: Way to create unique constraint in Postgres even with null columns

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Way to create unique constraint in Postgres even with null columns
Date: 2011-11-27 22:59:09
Message-ID: jaufbt$nga$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Johnston wrote on 27.11.2011 23:18:

> Also, the index example above presumes you want RecipeId to be "Null-able"
> as opposed to MenuId as described in your original post.
>

Well of course that was a typo in my answer, it should have been:

CREATE UNIQUE INDEX Favorites_UniqueFavorite
ON (UserId, RecipeId)
WHERE MenuId IS NULL;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-11-28 00:37:23 Re: Way to create unique constraint in Postgres even with null columns
Previous Message Mike Christensen 2011-11-27 22:43:42 Re: Way to create unique constraint in Postgres even with null columns