Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WnvU8-0008UN-IW for pgsql-bugs@arkaria.postgresql.org; Fri, 23 May 2014 19:50:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WnvEJ-0003tm-7w for pgsql-bugs@arkaria.postgresql.org; Fri, 23 May 2014 19:34:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WnvEH-0003rc-L5 for pgsql-bugs@postgresql.org; Fri, 23 May 2014 19:34:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WnvED-000628-Se for pgsql-bugs@postgresql.org; Fri, 23 May 2014 19:34:08 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s4NJY1SK012131; Fri, 23 May 2014 15:34:01 -0400 From: Tom Lane To: Claudio Nieder cc: pgsql-bugs@postgresql.org Subject: Re: BUG #10429: the same update return different result In-reply-to: References: <20140523074125.2687.92046@wrigleys.postgresql.org> <537F827F.8030303@ort.edu.uy> Comments: In-reply-to Claudio Nieder message dated "Fri, 23 May 2014 21:29:03 +0200" Date: Fri, 23 May 2014 15:34:05 -0400 Message-ID: <6125.1400873645@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) 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 Claudio Nieder writes: >>> postgres=# update t1 set c1 = c1 +1; >> This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. >> > My understanding would have been, that "update t1 set c1=c1+1;" is ONE command, so even in the NOT DEFERRABLE case the check would occur only after both values were changed and as such not find any violation of the constraint. The important detail is a bit further down the page, in the "Compatibility" section: 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