Re: Recreating unique index for primary key - Mailing list pgsql-general

From Tom Lane
Subject Re: Recreating unique index for primary key
Date
Msg-id 23177.1001774504@sss.pgh.pa.us
Whole thread Raw
In response to Recreating unique index for primary key  (Ryan Ho <ryanho@pacific.net.sg>)
Responses Re: Recreating unique index for primary key
List pgsql-general
Ryan Ho <ryanho@pacific.net.sg> writes:
> I've dropped an primary key index in order to re-create it. but i realized
> that i can't recreate a primary key index. Will a unique index be an adequate
> replacement? will the database integrity be at risk as a result?

CREATE UNIQUE INDEX is fine as far as the database goes.  Offhand it
looks like the only extra thing a primary-key marker does is to define
the default reference column for subsequent foreign-key references
pointing at your table.

If you want, you can reach into pg_index and set the indisprimary field
after creating the index:

update pg_index set indisprimary = true where indexrelid =
(select oid from pg_class where relname = 'yourindexname')

There's been some discussion of adding a PRIMARY option to CREATE INDEX
to allow doing this in a cleaner way, but it's not been done yet.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: trigger compile problem
Next
From: Tom Lane
Date:
Subject: Re: Encoding passwords