pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: richard coleman <rcoleman.ascentgl@gmail.com>
Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Why isn't there a IF NOT EXISTS clause on constraint creation?
Date: Wed, 30 Aug 2023 17:26:17 -0400
Message-ID: <226806.1693430777@sss.pgh.pa.us> (raw)
In-Reply-To: <CAGA3vBvFJuPjPK6K2L7htCmRKHGm4vm7YPpEsZaynP30Ps+UxQ@mail.gmail.com>
References: <CAGA3vBvFJuPjPK6K2L7htCmRKHGm4vm7YPpEsZaynP30Ps+UxQ@mail.gmail.com>

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





view thread (7+ messages)  latest in thread

Message-ID: <226806.1693430777@sss.pgh.pa.us>
Permalink:  ../226806.1693430777@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/226806.1693430777@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rcoleman.ascentgl@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: Why isn't there a IF NOT EXISTS clause on constraint creation?
  In-Reply-To: <226806.1693430777@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox