Having a 2-column uniqueness constraint - Mailing list pgsql-general

From VanL
Subject Having a 2-column uniqueness constraint
Date
Msg-id bfjl0r$prl$1@main.gmane.org
Whole thread Raw
Responses Re: Having a 2-column uniqueness constraint  ("Shridhar Daithankar" <shridhar_daithankar@persistent.co.in>)
Re: Having a 2-column uniqueness constraint  (Patrick Welche <prlw1@newn.cam.ac.uk>)
List pgsql-general
Hello,

I know that it is possible to have a 2-column primary key, which
enforces uniqueness of the combination of those two columns.  However,
for our schema, we need to have a single column (integer) primary key,
but we still wish to enforce uniqueness across two particular columns.

For example:

id (integer primary key) | domain_name (varchar (255)) | mid (other id)

The id is, as shown, the primary key.  The mid is the primary id of
another table (the management unit), with a foreign key constraint that
keeps the reference correct.

How can I make sure that the there is only one instance of a particular
domain name in each management unit?

Put another way, how can I set a (domain_name, mid) UNIQUE constraint?

Thanks,

VanL


pgsql-general by date:

Previous
From: Vivek Khera
Date:
Subject: Re: Checkpoint question
Next
From: "Shridhar Daithankar"
Date:
Subject: Re: Having a 2-column uniqueness constraint