Re: UNIQUE constraint - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: UNIQUE constraint
Date
Msg-id 7E5F5B5E-E996-11D8-B87D-000A95C88220@myrealbox.com
Whole thread Raw
In response to UNIQUE constraint  (Sascha Ziemann <ziemann@secunet.de>)
Responses Re: UNIQUE constraint
COMMENT ON CONSTRAINT
List pgsql-sql
On Aug 7, 2004, at 3:25 AM, Sascha Ziemann wrote:
> CREATE TABLE example (
>     a integer,
>     b integer,
>     c integer,
>     UNIQUE (a, c)
> );
>
> But it is not clean to me.  Does the above example mean that the list
> of pairs must be unique

Yes.

> Does the following table fullfill the UNIQUE clause of the example
> from the Postgres documentation?
>
>   a b c
>   -----
>   1 2 3
>   1 1 1

Yes.

For example,

test=# create table example (a integer, b integer, c integer, unique 
(a,c));
NOTICE:  CREATE TABLE / UNIQUE will create implicit index 
"example_a_key" for table "example"
CREATE TABLE
test=# insert into example (a,b,c) values (1,2,3);
INSERT 5935749 1
test=# insert into example (a,b,c) values (1,1,1);
INSERT 5935750 1
test=# insert into example (a,b,c) values (1,3,3);
ERROR:  duplicate key violates unique constraint "example_a_key"
test=# select a,b,c from example; a | b | c
---+---+--- 1 | 2 | 3 1 | 1 | 1
(2 rows)

Michael Glaesemann
grzm myrealbox com



pgsql-sql by date:

Previous
From: "Knut P Lehre"
Date:
Subject: select
Next
From: Josh Berkus
Date:
Subject: Re: surrogate key or not?