Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YiqC9-0004cq-Gf for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2015 20:15:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YiqC7-0004d0-Qv for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2015 20:15:27 +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 1Yiq1A-0002Hg-Cg for pgsql-bugs@postgresql.org; Thu, 16 Apr 2015 20:04:08 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yiq15-0001u8-Es for pgsql-bugs@postgresql.org; Thu, 16 Apr 2015 20:04:07 +0000 MIME-Version: 1.0 Subject: BUG #13073: Uniqueness constraint incorrectly reports constraint violations To: pgsql-bugs@postgresql.org From: dportas@acm.org Date: Thu, 16 Apr 2015 20:03:34 +0000 Message-ID: <20150416200334.5200.85645@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.2 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 13073 Logged by: David Portas Email address: dportas@acm.org PostgreSQL version: 9.1.13 Operating system: Debian Linux Description: Repro script: CREATE TABLE tbl1 (x INT NOT NULL PRIMARY KEY); INSERT INTO tbl1 VALUES (1),(2); UPDATE tbl1 SET x = x +1; Result: ERROR: duplicate key value violates unique constraint "tbl1_pkey" DETAIL: Key (x)=(2) already exists. Expected result: UPDATE should succeed because the constraint is not violated. The constraint should be evaluated against the complete resulting table as per documentation: "unique with respect to all the rows in the table"[1]. The expected result can be seen if the insertion order of the INSERTs is reversed: CREATE TABLE tbl1 (x INT NOT NULL PRIMARY KEY); INSERT INTO tbl1 VALUES (2),(1); UPDATE tbl1 SET x = x +1; Result: UPDATE succeeds. This is expected but is inconsistent with the previous result even though the two UPDATEs are logically equivalent. The same effect is seen if UNIQUE is specified instead of PRIMARY KEY. [1]http://www.postgresql.org/docs/9.1/static/ddl-constraints.html -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs