Re: EXCLUDE constraint with not equals

From: Kai Groner <kai(at)gronr(dot)com>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: EXCLUDE constraint with not equals
Date: 2015-02-10 13:15:54
Message-ID: CALiRuxmikT+c_XOHn2ODGYYw8Cx7SS6FCU42EyEmZzsYUjpjiQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Thomas,

The partial unique index would prevent multiple person records with the
same email. I want to allow that as long as they agree on the value of
user.

Kai

On Tue, Feb 10, 2015 at 2:14 AM, Thomas Kellerer <spam_eater(at)gmx(dot)net> wrote:

> Kai Groner schrieb am 10.02.2015 um 01:38:
> > Given the following table, I would like to ensure that all the rows for
> an email that have a user defined map to the same user.
> >
> > CREATE TABLE person (
> > id INTEGER PRIMARY KEY,
> > user TEXT,
> > email TEXT NOT NULL);
> >
> >
> > What I think I'm looking for is something like this:
> >
> > CREATE TABLE person (
> > id INTEGER PRIMARY KEY,
> > user TEXT,
> > email TEXT NOT NULL,
> > EXCLUDE (email WITH =, user WITH <>)
> > WHERE (user IS NOT NULL));
> >
> > The not equals comparison isn't supported, but it would be useful here.
> >
> > Is there another way to do this, short of creating a separate table that
> associates email and user?
>
> A partial unique index on (user, email) should do:
>
> create unique index on person (email, user)
> where user is not null;
>
> Thomas
>
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Drolet 2015-02-10 16:38:49 Re: Cluster seems broken after pg_basebackup
Previous Message Michael Paquier 2015-02-10 12:18:32 Re: Logical Decoding Callbacks