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 1iPTYV-0007FI-C8 for pgsql-bugs@arkaria.postgresql.org; Tue, 29 Oct 2019 15:37:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iPTYT-000600-W7 for pgsql-bugs@arkaria.postgresql.org; Tue, 29 Oct 2019 15:37:09 +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 1iPTYT-0005zt-OM for pgsql-bugs@lists.postgresql.org; Tue, 29 Oct 2019 15:37:09 +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 1iPTYR-0001ln-GK for pgsql-bugs@lists.postgresql.org; Tue, 29 Oct 2019 15:37:09 +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 x9TFb5A4023526; Tue, 29 Oct 2019 11:37:05 -0400 From: Tom Lane To: jsturgeon@novetta.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16088: Multiple foreigh keys created on "ALTER TABLE" command In-reply-to: <16088-d8dbfda0fb069e93@postgresql.org> References: <16088-d8dbfda0fb069e93@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 29 Oct 2019 15:26:19 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23524.1572363425.1@sss.pgh.pa.us> Date: Tue, 29 Oct 2019 11:37:05 -0400 Message-ID: <23525.1572363425@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > If you run this command multiple times: > ALTER TABLE myschema.mytable ADD IF NOT EXISTS mycolumn uuid REFERENCES > myschema.mytable2(userid); > It adds the column once, but adds a duplicate FOREIGN KEY each time. Yeah, this is a well known problem :-(. The IF NOT EXISTS conditionalizes addition of the column, but not the quasi-independent addition of the foreign key constraint. There's work afoot to make this behave more intuitively, but it won't land before v13 at the earliest. regards, tom lane