Re: [BUGS] BUG #14596: False primary/unique key constraint violations - Mailing list pgsql-bugs

From bricklen
Subject Re: [BUGS] BUG #14596: False primary/unique key constraint violations
Date
Msg-id CAGrpgQ_gMOSRCqNUiSQ1zF2McEvuMQU1UQ3rzYX8iLKeMgWPLA@mail.gmail.com
Whole thread Raw
In response to [BUGS] BUG #14596: False primary/unique key constraint violations  (rasmus@mindplay.dk)
List pgsql-bugs
On Wed, Mar 22, 2017 at 5:30 AM, <rasmus@mindplay.dk> wrote:

CREATE TABLE public.test
(
   name character varying(100),
   index integer,
   CONSTRAINT unique_index PRIMARY KEY (index)
);

And the following sample data:
INSERT INTO "test" ("name", "index") VALUES ('A', 0);
INSERT INTO "test" ("name", "index") VALUES ('B', 1);
INSERT INTO "test" ("name", "index") VALUES ('C', 2);

The following query will fail:
UPDATE "test" SET "index" = "index" + 1 WHERE "index" >= 0;

Try the following with a deferred constraint:

CREATE TABLE public.test
(
   name character varying(100),
   index integer,
   CONSTRAINT unique_index PRIMARY KEY (index) DEFERRABLE INITIALLY DEFERRED
);


pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #14596: False primary/unique key constraint violations
Next
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #14597: Delay in query execution