Re: Asserting existing key to be primary

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chris Browne <cbbrowne(at)acm(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Asserting existing key to be primary
Date: 2004-08-13 19:24:16
Message-ID: 26174.1092425056@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chris Browne <cbbrowne(at)acm(dot)org> writes:
> I have a table that has a candidate primary key (e.g. - unique, not
> null) that I wish to actually assert _is_ a primary key.

> Is there a way to do that without too much (mwahahhaha! fiddling with
> pg_class!!!) trickery?

Why don't you just ALTER TABLE ADD PRIMARY KEY and then drop the
existing unique constraint?

You could probably fool with pg_constraint and pg_index to manually
transform the unique constraint into a pkey constraint, but the odds
of messing it up seem to outweigh the possible time savings.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Gaetano Mendola 2004-08-13 19:45:36 Re: hot spare / log shipping work on
Previous Message Tom Lane 2004-08-13 19:20:56 Re: Referencing OLD/NEW Rows on Trigger Definition