Re: brain-teaser with CONSTRAINT - any SQL experts?

From: Miles Keaton <mileskeaton(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: brain-teaser with CONSTRAINT - any SQL experts?
Date: 2005-10-10 03:25:31
Message-ID: 59b2d39b0510092025l7dfc2330u9074f2295943d645@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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');

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2005-10-10 03:31:09 Re: Oracle buys Innobase
Previous Message Rick Morris 2005-10-10 03:22:33 Re: Oracle buys Innobase