Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k9WWN-0004bF-B4 for pgsql-bugs@arkaria.postgresql.org; Sat, 22 Aug 2020 16:37:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k9WWM-00068Z-8W for pgsql-bugs@arkaria.postgresql.org; Sat, 22 Aug 2020 16:37:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k9WWM-00068S-26 for pgsql-bugs@lists.postgresql.org; Sat, 22 Aug 2020 16:37:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k9WWI-0004Ut-Py for pgsql-bugs@lists.postgresql.org; Sat, 22 Aug 2020 16:37:33 +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 07MGbRKJ2206634; Sat, 22 Aug 2020 12:37:27 -0400 From: Tom Lane To: jeremyevans0@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16589: Regression when using ADD UNIQUE+ADD FOREIGN KEY in same query in 13 beta In-reply-to: <16589-31c8d981ca503896@postgresql.org> References: <16589-31c8d981ca503896@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 21 Aug 2020 20:54:58 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2206632.1598114247.1@sss.pgh.pa.us> Date: Sat, 22 Aug 2020 12:37:27 -0400 Message-ID: <2206633.1598114247@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > The following SQL worked as expected in previous PostgreSQL versions (at > least 8.4-12): > CREATE TABLE "items" ("id" integer NOT NULL, "item_id" integer NOT > NULL); > ALTER TABLE "items" ADD UNIQUE ("item_id", "id"), ADD FOREIGN KEY ("id", > "item_id") REFERENCES "items"("item_id", "id"); > In PostgreSQL 13 beta 3, it results in an error: there is no unique > constraint matching given keys for referenced table "items" Yup, that's my fault; fix pushed. > I'm not sure whether this is considered a bug. It broke a couple tests for > a database access library I maintain, but I could easily modify them if this > isn't considered a bug. Yeah, I think it's a bug, especially since the case used to work. ALTER TABLE generally believes that it's smarter than you are about the order in which the subcommands need to be executed; so it has to hold up its end of the bargain. regards, tom lane