Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cqhWO-0004qT-Fu for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Mar 2017 14:45:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cqhWN-0006hE-VT for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Mar 2017 14:45:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cqhVg-0004gb-AZ for pgsql-bugs@postgresql.org; Wed, 22 Mar 2017 14:45:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cqhVd-0001nZ-AO for pgsql-bugs@postgresql.org; Wed, 22 Mar 2017 14:45:11 +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 v2MEj7Xv031318; Wed, 22 Mar 2017 10:45:07 -0400 From: Tom Lane To: rasmus@mindplay.dk cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14596: False primary/unique key constraint violations In-reply-to: <20170322123053.1421.55154@wrigleys.postgresql.org> References: <20170322123053.1421.55154@wrigleys.postgresql.org> Comments: In-reply-to rasmus@mindplay.dk message dated "Wed, 22 Mar 2017 12:30:53 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31316.1490193907.1@sss.pgh.pa.us> Date: Wed, 22 Mar 2017 10:45:07 -0400 Message-ID: <31317.1490193907@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 rasmus@mindplay.dk writes: > It looks like constraints are being checked row-by-row while the udpate is > happening? This is documented somewhere ... ah, here, in the COMPATIBILITY section of the CREATE TABLE reference page: Non-deferred Uniqueness Constraints When a UNIQUE or PRIMARY KEY constraint is not deferrable, PostgreSQL checks for uniqueness immediately whenever a row is inserted or modified. The SQL standard says that uniqueness should be enforced only at the end of the statement; this makes a difference when, for example, a single command updates multiple key values. To obtain standard-compliant behavior, declare the constraint as DEFERRABLE but not deferred (i.e., INITIALLY IMMEDIATE). Be aware that this can be significantly slower than immediate uniqueness checking. 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