From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
---|---|
To: | Sascha Ziemann <ziemann(at)secunet(dot)de> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: UNIQUE constraint |
Date: | 2004-08-08 23:55:58 |
Message-ID: | 7E5F5B5E-E996-11D8-B87D-000A95C88220@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2004-08-09 03:40:35 | Re: Make a column case insensitive |
Previous Message | Josh Berkus | 2004-08-08 22:19:16 | Re: surrogate key or not? |