Re: Why isn't there a IF NOT EXISTS clause on constraint creation?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: richard coleman <rcoleman(dot)ascentgl(at)gmail(dot)com>
Cc: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Why isn't there a IF NOT EXISTS clause on constraint creation?
Date: 2023-08-30 21:26:17
Message-ID: 226806.1693430777@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

richard coleman <rcoleman(dot)ascentgl(at)gmail(dot)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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message richard coleman 2023-08-31 13:00:45 Re: Why isn't there a IF NOT EXISTS clause on constraint creation?
Previous Message richard coleman 2023-08-30 20:38:53 Why isn't there a IF NOT EXISTS clause on constraint creation?