From: dportas@acm.org
To: pgsql-bugs@postgresql.org
Subject: BUG #13073: Uniqueness constraint incorrectly reports constraint violations
Date: Thu, 16 Apr 2015 20:03:34 +0000
Message-ID: <20150416200334.5200.85645@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: dportas@acm.org
Subject: Re: BUG #13073: Uniqueness constraint incorrectly reports constraint violations
In-Reply-To: <20150416200334.5200.85645@wrigleys.postgresql.org>
References: <20150416200334.5200.85645@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox