Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2dTM-0004V5-Ja for pgsql-bugs@arkaria.postgresql.org; Tue, 27 Aug 2019 15:33:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i2dTL-0008Nu-FR for pgsql-bugs@arkaria.postgresql.org; Tue, 27 Aug 2019 15:33:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2dTL-0008Kc-6c for pgsql-bugs@lists.postgresql.org; Tue, 27 Aug 2019 15:33:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2dTI-0002KI-GV for pgsql-bugs@lists.postgresql.org; Tue, 27 Aug 2019 15:33:26 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7RFXLd3013278; Tue, 27 Aug 2019 11:33:21 -0400 From: Tom Lane To: e.oneal89@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15981: Alter table add column if not exists with constraint fails on constraint In-reply-to: <15981-1c21384db6d3e7f1@postgresql.org> References: <15981-1c21384db6d3e7f1@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 27 Aug 2019 15:07:01 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13276.1566920001.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 27 Aug 2019 11:33:21 -0400 Message-ID: <13277.1566920001@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > CREATE TABLE test(id uuid PRIMARY KEY); > ALTER TABLE test ADD IF NOT EXISTS id uuid PRIMARY KEY; > Output: `NOTICE: column "id" of relation "test" already exists, skippin= g > ERROR: multiple primary keys for table "test" are not allowed` Yeah, this is a well-known issue: the IF NOT EXISTS only conditionalizes creation of the column, but it's reasonable to expect that it should conditionalize creation of the index as well. There's work afoot to improve this [1], but it's not moving very fast; at the earliest you might see it fixed in v13. regards, tom lane [1] https://www.postgresql.org/message-id/flat/10365.1558909428%40sss.pgh.= pa.us