Having a 2-column uniqueness constraint

From: VanL <vlindberg(at)verio(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Having a 2-column uniqueness constraint
Date: 2003-07-22 15:29:44
Message-ID: bfjl0r$prl$1@main.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bob Nix 2003-07-22 15:30:02 pg_dump problem
Previous Message Richard Huxton 2003-07-22 15:20:25 Re: can anybody help me please