Search Postgresql Archives

Re: EXCLUDE constraint with not equals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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?

You can use the btree_gist extension from contrib:

CREATE EXTENSION btree_gist;

CREATE TABLE person (
  id INTEGER PRIMARY KEY,
  "user" TEXT,
  email TEXT NOT NULL,
  EXCLUDE USING gist (email WITH =, "user" WITH <>)
    WHERE ("user" IS NOT NULL));


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux