Re: UNIQUE constraint

Re: UNIQUE constraint

am 09.08.2004 01:55:58 von grzm

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


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Re: COMMENT ON CONSTRAINT

am 16.08.2004 03:03:32 von seltenreich

Sascha Ziemann writes:

> it is defined in this way:
[...]
> CONSTRAINT constraint_name ON table_name |

Well then...

> comment on constraint uni on table tab3 is 'unique pair';
^^^^^
....why do you insert "table" when it is defined without? :-)

regards
Andreas

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend