dbTalk Databases Forums  

unique constraint on multiple colums does not work

comp.databases.postgresql comp.databases.postgresql


Discuss unique constraint on multiple colums does not work in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default unique constraint on multiple colums does not work - 01-21-2008 , 05:27 AM






Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of
them are not primary keys). I mean that 2 rows are different when at
least one of the two above columns is different. The problem is that
Postgres enforce the constraint also when only one of the columns is
equal to another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?

Reply With Quote
  #2  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM







"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #3  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM




"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #4  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM




"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #5  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM




"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #6  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM




"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #7  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM




"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #8  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM




"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #9  
Old   
Luuk
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 07:05 AM




"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef in bericht
news:47948219$0$16044$5fc30a8 (AT) news (DOT) tiscali.it...
Quote:
Hello there,
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
<unknown>
CONSTRAINT if_uniq UNIQUE (name, device)
)
;





Reply With Quote
  #10  
Old   
Lew
 
Posts: n/a

Default Re: unique constraint on multiple colums does not work - 01-21-2008 , 11:16 AM



"Coniglio Sgabbiato" <nobody (AT) nowhere (DOT) it> schreef
Quote:
I need to enforce a unique constraint on 2 colums of a table (both of them
are not primary keys). I mean that 2 rows are different when at least one
of the two above columns is different. The problem is that Postgres
enforce the constraint also when only one of the columns is equal to
another row, see below the creation code i used for:

alter table interfaces add constraint if_uniq unique (name, device);

but this constraint raise an error when, for example i try to insert two
rows with values:

insert into interfaces (name, device) values ('141', 646);
insert into interfaces (name, device) values ('141', 637);

is this a bug in Postgres? is there a solution?
No. Yes.

Luuk wrote:
Quote:
can you post the definition of your table, so we can see what's <unknown> to
us?

CREATE TABLE interfaces
(
unknown
CONSTRAINT if_uniq UNIQUE (name, device)
)
;
Also, could you post the *exact* text (preferably through a copy-and-paste) of
the error message?

--
Lew


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.