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 1fwVkA-0007jY-Ig for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 17:00:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fwVk7-000162-OB for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 17:00:55 +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 1fwVk7-00015v-I5 for pgsql-bugs@lists.postgresql.org; Sun, 02 Sep 2018 17:00:55 +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 1fwVk0-0002Oa-Gt for pgsql-bugs@postgresql.org; Sun, 02 Sep 2018 17:00:55 +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 w82H0jqe010111; Sun, 2 Sep 2018 13:00:46 -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: <87in3ovy0r.fsf@news-spur.riddles.org.uk> References: <0c1001d4428f$0942b430$1bc81c90$@webkr.de> <87in3ovy0r.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Sun, 02 Sep 2018 14:22:56 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <10109.1535907645.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Sun, 02 Sep 2018 13:00:45 -0400 Message-ID: <10110.1535907645@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. This also points up the lack of a suitable unique index on pg_constraint. It's sort of difficult to figure out what that should look like given that pg_constraint contains two quasi-independent collections of constraints, but maybe UNIQUE(conrelid,contypid,conname) would serve given the reasonable assumption that exactly one of conrelid and contypid is zero. Potentially we could drop pg_constraint_conrelid_index and pg_constraint_contypid_index, replacing scans on those with scans on this new unique index. regards, tom lane