Why isn't there a IF NOT EXISTS clause on constraint creation? - Mailing list pgsql-admin

From richard coleman
Subject Why isn't there a IF NOT EXISTS clause on constraint creation?
Date
Msg-id CAGA3vBvFJuPjPK6K2L7htCmRKHGm4vm7YPpEsZaynP30Ps+UxQ@mail.gmail.com
Whole thread Raw
Responses Re: Why isn't there a IF NOT EXISTS clause on constraint creation?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-admin
I find myself having to check a couple of hundred tables and add the primary keys back in, if they don't exist.

While there's a IF NOT EXISTS clause on the DROP statement to drop a constraint, like a primary key, inexplicably there isn't one on the ALTER TABLE statement that creates them.

The internet is littered with people asking about this, some going back years.  The responses range from manually checking first, using a DROP IF EXISTS statement first, to writing various blocks of PL/pgSQL code.

Why doesn't ALTER TABLE ...  ADD CONSTRAINT not come with an ALTER TABLE ... ADD CONSTRAINT IF NOT EXISTS variant?

Could one be added?

Just wondering, 
rik.

pgsql-admin by date:

Previous
From: Nikhil Shetty
Date:
Subject: Logical Replication hung: logical_decoding_work_mem over utilised
Next
From: Tom Lane
Date:
Subject: Re: Why isn't there a IF NOT EXISTS clause on constraint creation?