Re: how to add primary key to existing table with multiple primary keys

From: "Mauricio Fernandez A(dot)" <mfacontacto(at)ono(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: how to add primary key to existing table with multiple primary keys
Date: 2006-03-01 10:17:15
Message-ID: CMEIKGCPKOPCGFKCNHLDAEKLCDAA.mfacontacto@ono.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Your table has a primary key yet, so you can?t add a second primary key.
You only can define one pk, however it can be composed as your table has (it
now has 2 columns), so I think you need to drop the current pk and add again
the new pk with your 3 columns (probeid, tissueid, expid).

Review this
http://www.postgresql.org/docs/8.1/interactive/ddl-constraints.html#AEN2038

Mauricio Fernandez A.
Ingeniero de Sistemas
Universidad Autonoma de Manizales (Colombia)

-----Mensaje original-----
De: pgsql-sql-owner(at)postgresql(dot)org
[mailto:pgsql-sql-owner(at)postgresql(dot)org]En nombre de Daniel Joo
Enviado el: viernes, 24 febrero, 2006 2:45
Para: pgsql-sql(at)postgresql(dot)org
Asunto: [SQL] how to add primary key to existing table with multiple
primary keys

Hi there,

I am trying to add another primary key to an existing table with two other
primary keys. I got the following error when I tried this command:

alter table extprobe2tissue ADD primary key (expid);

ERROR: multiple primary keys for table "extprobe2tissue" are not allowed

The details of the extprobe2tissue table is:

\d extprobe2tissue;

Table "public.extprobe2tissue"

Column | Type | Modifiers

-------------+------------------------+-----------

probeid | integer | not null

tissueid | integer | not null

value | double precision | not null

entrydate | date | not null

description | character varying(200) |

qval | double precision |

expid | integer | not null

Indexes:

"extprobe2tissue_pkey" PRIMARY KEY, btree (probeid, tissueid)

"extprobe2tissue_probeid" btree (probeid)

"extprobe2tissue_tissueid" btree (tissueid)

Foreign-key constraints:

"extprobe2tissue_tissueid_fkey" FOREIGN KEY (tissueid) REFERENCES
tissue(tissueid)

"extprobe2tissue_probeid_fkey" FOREIGN KEY (probeid) REFERENCES
extprobe(probeid)

Any suggestion would be much appreciated.

Thanks!

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message A. Kretschmer 2006-03-01 11:33:01 Re: Index to support LIKE '%suffix' queries
Previous Message Florian Weimer 2006-03-01 07:19:40 Re: Index to support LIKE '%suffix' queries