Re: Replacing an existing unique constraint (not UNIQUE INDEX) with primary key

From: Andreas Joseph Krogh <andreas(at)visena(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Replacing an existing unique constraint (not UNIQUE INDEX) with primary key
Date: 2016-12-20 11:03:14
Message-ID: VisenaEmail.25.b9c2bfd5968f8f3b.1591be44345@tc7-visena
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

På tirsdag 20. desember 2016 kl. 11:42:56, skrev Achilleas Mantzios <
achill(at)matrix(dot)gatewaynet(dot)com <mailto:achill(at)matrix(dot)gatewaynet(dot)com>>:
On 20/12/2016 12:27, Andreas Joseph Krogh wrote:
På tirsdag 20. desember 2016 kl. 11:02:27, skrev Achilleas Mantzios <
achill(at)matrix(dot)gatewaynet(dot)com <mailto:achill(at)matrix(dot)gatewaynet(dot)com>>:
On 20/12/2016 11:43, Andreas Joseph Krogh wrote:
[snip]
BEGIN;
ALTER TABLE person ADD CONSTRAINT person_pk PRIMARY KEY (entity_id);
alter table person drop constraint person_entity_id_key CASCADE;
alter table phone add CONSTRAINT phone_fk FOREIGN KEY (person_entity_id)
REFERENCES person(entity_id);
alter table address add CONSTRAINT address_fk FOREIGN KEY (person_id)
REFERENCES person(entity_id);
COMMIT;  
Yea, I was hoping to avoid having to manually add the FK's to the referencing
tables (34).
Is there really no way to accomplish this without DROP CONSTRAINT ...
 CASCADE, hacking the system-catalogs or something?
 
You may write a script to output those 34 FK constraints. Definitely safer
than hacking pg_constraint.conindid   
Yes.
 
I'd still argue that what I'm trying to do should "just work" as PG treats
UNIQUE CONSTRAINT and UNIQUE INDEX the same wrt. the planner and FK-enforcement.
 
-- Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com>
<https://www.visena.com>

 

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2016-12-20 15:17:35 Re: Replacing an existing unique constraint (not UNIQUE INDEX) with primary key
Previous Message Mickaël Le Baillif 2016-12-20 10:59:29 Re: JSON objects merge using || operator