Re: Multiple Primary Keys - Mailing list pgsql-novice

From Josh Berkus
Subject Re: Multiple Primary Keys
Date
Msg-id web-1375947@davinci.ethosmedia.com
Whole thread Raw
In response to Multiple Primary Keys  ("samsom, debra" <dsamsom@bristol.ca>)
Responses Altering psqlodbc.h  ("Jillian Carroll" <jillian@koskie.com>)
List pgsql-novice
Debra,

> Currently I have a table on Microsoft Sequel Server that I wish to
> port over
> to Postgresql.   This table has four primary keys and it's the
> combination
> of the four fields that make the record unique.

Just to get your terminology straight:  What you have is a *single*
primary key, consisting of four fields.  You cannot have more than one
primary key for a table.  I would strongly suggest that you re-consider
your database design: composite primary keys (which is what you have)
are a *lot* of trouble.

A surrogate key (such as an auto-incrementing integer) would be much
easier to handle.  For more information, I strongly reccomend the book
"Database Design for Mere Mortals."

> "Cannot insert a duplicate key into unique index attachments_pkey"

Yes.  You have duplicate data somewhere in the table.  The primary key
must be unique.  Try this:

SELECT "docn","issue","docna","issuea", count(*) FROM attachments
GROUP BY "docn","issue","docna","issuea"
HAVING count(*) > 1;

This should list all of your duplicates.    If you get a "NULL Value
Eliminated From Aggregate" warning, that means that one or more of
those columns has a NULL value, which must either be filled in, or you
must exclude it fromm the Primary Key.

-Josh Berkus



pgsql-novice by date:

Previous
From: "samsom, debra"
Date:
Subject: Multiple Primary Keys
Next
From: "Josh Berkus"
Date:
Subject: Re: Multiple Primary Keys