Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qbShl-00C7KR-8C for pgsql-admin@arkaria.postgresql.org; Wed, 30 Aug 2023 21:26:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qbShj-002C9d-Pb for pgsql-admin@arkaria.postgresql.org; Wed, 30 Aug 2023 21:26:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qbShj-002C9Q-84 for pgsql-admin@lists.postgresql.org; Wed, 30 Aug 2023 21:26:23 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qbShf-001qkp-Oz for pgsql-admin@lists.postgresql.org; Wed, 30 Aug 2023 21:26:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 37ULQHvv226807; Wed, 30 Aug 2023 17:26:17 -0400 From: Tom Lane To: richard coleman cc: Pgsql-admin Subject: Re: Why isn't there a IF NOT EXISTS clause on constraint creation? In-reply-to: References: Comments: In-reply-to richard coleman message dated "Wed, 30 Aug 2023 16:38:53 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <226805.1693430777.1@sss.pgh.pa.us> Date: Wed, 30 Aug 2023 17:26:17 -0400 Message-ID: <226806.1693430777@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk richard coleman 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