Re: brain-teaser with CONSTRAINT - any SQL experts? - Mailing list pgsql-general

From Miles Keaton
Subject Re: brain-teaser with CONSTRAINT - any SQL experts?
Date
Msg-id 59b2d39b0510092025l7dfc2330u9074f2295943d645@mail.gmail.com
Whole thread Raw
In response to Re: brain-teaser with CONSTRAINT - any SQL experts?  (Keary Suska <hierophant@pcisys.net>)
List pgsql-general
> I would create a multi-column unique index on the table. This should solve
> the problem mentioned although you may still have an integrity issue if a
> "book" name is mistyped.

Hm?

This sounds promising, except it's the exact opposite of what I need.

Is this what you meant?

CREATE TABLE lineitems (code int, name varchar(12), UNIQUE (code, name));

Because that breaks the whole idea where I should be able to have many
lines with the same item:

insert into lineitems(code, name) VALUES (123, 'bob');
INSERT 35489 1
insert into lineitems(code, name) VALUES (123, 'bob');
ERROR:  duplicate key violates unique constraint "lineitems_code_key"

What I want is for that situation, above, to NOT make an error.
But this, below, should:

insert into lineitems(code, name) VALUES (123, 'bob');
insert into lineitems(code, name) VALUES (123, 'xxx');

pgsql-general by date:

Previous
From: Miles Keaton
Date:
Subject: Re: brain-teaser with CONSTRAINT - any SQL experts?
Next
From: "Marc G. Fournier"
Date:
Subject: Re: Oracle buys Innobase