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

From Tom Lane
Subject Re: Why isn't there a IF NOT EXISTS clause on constraint creation?
Date
Msg-id 226806.1693430777@sss.pgh.pa.us
Whole thread Raw
In response to Why isn't there a IF NOT EXISTS clause on constraint creation?  (richard coleman <rcoleman.ascentgl@gmail.com>)
Responses Re: Why isn't there a IF NOT EXISTS clause on constraint creation?  (richard coleman <rcoleman.ascentgl@gmail.com>)
List pgsql-admin
richard coleman <rcoleman.ascentgl@gmail.com> writes:
> Why doesn't ALTER TABLE ...  ADD CONSTRAINT not come with an ALTER TABLE
> ... ADD CONSTRAINT IF NOT EXISTS variant?

There's a general allergy in this project to CREATE IF NOT EXISTS,
because it's a foot-gun.  If the command succeeds, you know that
an object (constraint or whatever) by that name exists, but you
have no right to assume anything whatsoever about its properties.

CREATE OR REPLACE semantics are a lot less squishy.  Would a
command of that form solve your problem?  (I'm not sure about
a pleasing way to write that within ALTER TABLE, but this gripe
is about semantics not syntax.)

            regards, tom lane



pgsql-admin by date:

Previous
From: richard coleman
Date:
Subject: Why isn't there a IF NOT EXISTS clause on constraint creation?
Next
From: richard coleman
Date:
Subject: Re: Why isn't there a IF NOT EXISTS clause on constraint creation?