Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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');

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux