Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwWud-0002HF-PT for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 18:15:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fwWua-0001Xe-D0 for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 18:15:48 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwWua-0001XW-6o for pgsql-bugs@lists.postgresql.org; Sun, 02 Sep 2018 18:15:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwWuX-000422-6a for pgsql-bugs@postgresql.org; Sun, 02 Sep 2018 18:15:47 +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 w82IFggd013719; Sun, 2 Sep 2018 14:15:43 -0400 From: Tom Lane To: Andrew Gierth cc: =?utf-8?B?QW5kcsOpIEjDpG5zZWw=?= , pgsql-bugs@postgresql.org Subject: Re: Two constraints with the same name not always allowed In-reply-to: <10110.1535907645@sss.pgh.pa.us> References: <0c1001d4428f$0942b430$1bc81c90$@webkr.de> <87in3ovy0r.fsf@news-spur.riddles.org.uk> <10110.1535907645@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 02 Sep 2018 13:00:45 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <13717.1535912142.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Sun, 02 Sep 2018 14:15:42 -0400 Message-ID: <13718.1535912142@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > Andrew Gierth writes: >> "André" == André Hänsel writes: >> André> Case 2: >> André> CREATE TABLE t(c integer); >> André> ALTER TABLE t ADD CONSTRAINT foo CHECK(c > 1); >> André> ALTER TABLE t ADD CONSTRAINT foo UNIQUE(c); >> André> -> Creates two constraints, both called "foo". >> I'd call _that_ a bug, myself - having two constraints on a table with >> the same name potentially messes up a lot of automated maintenance >> operations. > Agreed. We must have missed a check for constraint-exists someplace. Note that if you repeat that last command, what you get is regression=# ALTER TABLE t ADD CONSTRAINT foo UNIQUE(c); ERROR: relation "foo" already exists I think the code supposes that checking for duplicate relation name is sufficient; but of course it is not if we want a table's constraints to have distinct names, since they may not all correspond to indexes. I do not think we can back-patch a change here --- it might break databases that are working satisfactorily today. But it seems like we could tighten this up in HEAD and maybe v11. regards, tom lane