Discussion:
no dup rows
(too old to reply)
Jodi Kanter
2004-08-02 18:32:54 UTC
Permalink
I have a linking table that has only two fields in it and both are
foreign keys to other tables. I'd like to ensure that there are never
any duplicate rows in this table. I was planning on creating a
multi-column unique index to satisfy this requirement. Is there a more
appropriate way to accomplish this or am I on the right track?>
thanks.
Jodi
--
_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
***@virginia.edu <mailto:***@virginia.edu100>
Bill Harper
2004-08-02 19:05:42 UTC
Permalink
Post by Jodi Kanter
I have a linking table that has only two fields in it and both are
foreign keys to other tables. I'd like to ensure that there are never
any duplicate rows in this table. I was planning on creating a
multi-column unique index to satisfy this requirement. Is there a more
appropriate way to accomplish this or am I on the right track?>
thanks.
Jodi
--
/_______________________________
//Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
Just create a primary key on the two columns, that way you get
uniqueness and not null constraints.

-bill


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
Reece Hart
2004-08-02 19:09:52 UTC
Permalink
Post by Jodi Kanter
I have a linking table that has only two fields in it and both are
foreign keys to other tables. I'd like to ensure that there are never
any duplicate rows in this table. I was planning on creating a
multi-column unique index to satisfy this requirement. Is there a more
appropriate way to accomplish this or am I on the right track?>
Yep, that is the correct way to impose this constraint.

I give constraints meaningful names prefixed by the table name (e.g.,
tablename_seq_already_in_set) so that the cause of an error is more
readily identifiable. This is particularly useful for insertions into
complex tables with multiple constraints.

-Reece
--
Reece Hart, Ph.D. ***@gene.com, http://www.gene.com/
Genentech, Inc. 650-225-6133 (voice), -5389 (fax)
Bioinformatics and Protein Engineering
1 DNA Way, MS-93 http://www.in-machina.com/~reece/
S. San Francisco, CA 94080-4990 ***@in-machina.com, GPG: 0x25EC91A0
Peter Eisentraut
2004-08-02 19:01:44 UTC
Permalink
Post by Jodi Kanter
I have a linking table that has only two fields in it and both are
foreign keys to other tables. I'd like to ensure that there are never
any duplicate rows in this table. I was planning on creating a
multi-column unique index to satisfy this requirement. Is there a
more appropriate way to accomplish this or am I on the right track?>
In "linking tables" you should usually make the entire set of columns
the primary key. This would solve your problem.
--
Peter Eisentraut
http://developer.postgresql.org/~petere/


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ***@postgresql.org)
Loading...