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

From Patrick Welche
Subject Re: Having a 2-column uniqueness constraint
Date
Msg-id 20030722172158.F10568@quartz.newn.cam.ac.uk
Whole thread Raw
In response to Having a 2-column uniqueness constraint  (VanL <vlindberg@verio.net>)
List 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

pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [BUGS] INSTEAD rule bug?
Next
From: Rory Campbell-Lange
Date:
Subject: using EXISTS instead of IN: how?