Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUcRh-000394-W6 for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Jul 2017 17:26:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dUcRh-0001EM-3N for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Jul 2017 17:26:05 +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.84_2) (envelope-from ) id 1dUcQx-00079A-Kk for pgsql-bugs@postgresql.org; Mon, 10 Jul 2017 17:25:19 +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.84_2) (envelope-from ) id 1dUcQq-0008LA-Bo for pgsql-bugs@postgresql.org; Mon, 10 Jul 2017 17:25:19 +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 v6AHPArt004339; Mon, 10 Jul 2017 13:25:10 -0400 From: Tom Lane To: "David G. Johnston" cc: "pgsql-bugs@postgresql.org" Subject: Re: Deferrable constraint execution not respecting "initially immediate"? In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Mon, 10 Jul 2017 10:00:23 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <4337.1499707510.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 10 Jul 2017 13:25:10 -0400 Message-ID: <4338.1499707510@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org "David G. Johnston" writes: > On Mon, Jul 10, 2017 at 9:25 AM, Tom Lane wrote: >> The solution for that is documented: declare the unique constraint as >> deferrable. >> >> regression=# CREATE TABLE T_UNIK (ID INT UNIQUE deferrable ); >> CREATE TABLE >> regression=# INSERT INTO T_UNIK VALUES (1), (2), (3), (4), (5); >> INSERT 0 5 >> regression=# UPDATE T_UNIK SET ID = ID + 1; >> UPDATE 5 > ​I was expecting the above to require a "set constraints deferred" since > "initially immediate" is the default. Right, but "deferrable initially immediate" still means "at the end of the statement", not "after each row". "deferrable initially deferred" means "at the end of the transaction". In this example there's no real difference between those two behaviors. > From "CREATE TABLE": > "A constraint that is not deferrable will be checked immediately after > every command." > I think the above should be "after every row" instead of "after every > command". I believe that FK constraints work differently from indexes in this regard. Not sure that we want to get into that level of detail here. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs