EXCLUDE constraint with not equals

From: Kai Groner <kai(at)gronr(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: EXCLUDE constraint with not equals
Date: 2015-02-10 00:38:38
Message-ID: CALiRux=zZatOsKKN3kHG0rnEHSatusz79_SHKBDsZ+1D4_2fpg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

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?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Xavier Stevens 2015-02-10 00:52:59 Logical Decoding Callbacks
Previous Message Michael Paquier 2015-02-10 00:09:27 Re: Mult-standby streaming replication master failover