sql - How to turn a Unique Constraint into a Primary key in PostgreSQL? -



sql - How to turn a Unique Constraint into a Primary key in PostgreSQL? -

i have table has primary key on columns, , unique constraint on column. dropped old primary key, , want create existing unique constraint new primary key of table, without dropping/rebuilding scratch.

the situation right this:

indexes: "t_review_routing_id_key" unique constraint, btree (id)

when run:

alter table t_review_routing add together primary key using index t_review_routing_id_key;

it says:

error: index "t_review_routing_id_key" associated constraint line 1: alter table t_review_routing add together primary key using index t_r...

i tried alter table t_review_routing add together constraint t_review_routing_id_pkey primary key using index t_review_routing_id_key;, same error.

any ideas?

you can drop existing constraint before creating new one, dropping constraint create index disappear too.

but, can create new index concurrently (example docs):

create unique index concurrently dist_id_temp_idx on distributors (dist_id); alter table distributors drop constraint distributors_pkey, add together constraint distributors_pkey primary key using index dist_id_temp_idx;

this method explicitly mentioned @ docs of alter table ... add together table_constraint_using_index.

sql postgresql

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -