Add PK constraint to a Unique Index via updating system catalogs?

Started by CS DBAover 12 years ago3 messagesgeneral
Jump to latest
#1CS DBA
cs_dba@consistentstate.com

Hi All;

We have a few very large tables with unique indexes on a column but the
column is not defined as the Primary Key. Can we add a PK constraint
via updates to the system catalogs so we can avoid the lengthy checks
that would take place if we ran "alter table add constraint primary key...."

Thanks in advance

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Thomas Kellerer
spam_eater@gmx.net
In reply to: CS DBA (#1)
Re: Add PK constraint to a Unique Index via updating system catalogs?

CS DBA wrote on 06.01.2014 23:30:

We have a few very large tables with unique indexes on a column but
the column is not defined as the Primary Key. Can we add a PK
constraint via updates to the system catalogs so we can avoid the
lengthy checks that would take place if we ran "alter table add
constraint primary key...."

You can add a PK constraint with the "USING INDEX" clause:

alter table foo
add primary key
using index unique_index_name;

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3CS DBA
cs_dba@consistentstate.com
In reply to: Thomas Kellerer (#2)
Re: Add PK constraint to a Unique Index via updating system catalogs?

Any way to add a PK "under the covers" for PostgreSQL version 8.3?

On 01/06/2014 03:53 PM, Thomas Kellerer wrote:

CS DBA wrote on 06.01.2014 23:30:

We have a few very large tables with unique indexes on a column but
the column is not defined as the Primary Key. Can we add a PK
constraint via updates to the system catalogs so we can avoid the
lengthy checks that would take place if we ran "alter table add
constraint primary key...."

You can add a PK constraint with the "USING INDEX" clause:

alter table foo
add primary key
using index unique_index_name;

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general