Re: Having a 2-column uniqueness constraint

From: Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
To: VanL <vlindberg(at)verio(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Having a 2-column uniqueness constraint
Date: 2003-07-22 16:21:58
Message-ID: 20030722172158.F10568@quartz.newn.cam.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jul 22, 2003 at 09:29:44AM -0600, VanL wrote:
...
> Put another way, how can I set a (domain_name, mid) UNIQUE constraint?

eg:

tree=# create table a ( a1 integer not null, a2 integer not null);
CREATE TABLE
tree=# create unique index a_idx on a(a1,a2);
CREATE INDEX
tree=# \d a
Table "public.a"
Column | Type | Modifiers
--------+---------+-----------
a1 | integer | not null
a2 | integer | not null
Indexes: a_idx unique btree (a1, a2)

tree=# insert into a values (1,2);
INSERT 43341961 1
tree=# insert into a values (1,3);
INSERT 43341962 1
tree=# insert into a values (1,2);
ERROR: Cannot insert a duplicate key into unique index a_idx

Cheers,

Patrick

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rory Campbell-Lange 2003-07-22 16:28:45 using EXISTS instead of IN: how?
Previous Message Bruce Momjian 2003-07-22 16:02:34 Re: [GENERAL] INSTEAD rule bug?