Re: BUG #14596: False primary/unique key constraint violations

From: bricklen <bricklen(at)gmail(dot)com>
To: rasmus(at)mindplay(dot)dk
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14596: False primary/unique key constraint violations
Date: 2017-03-22 14:50:48
Message-ID: CAGrpgQ_gMOSRCqNUiSQ1zF2McEvuMQU1UQ3rzYX8iLKeMgWPLA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Mar 22, 2017 at 5:30 AM, <rasmus(at)mindplay(dot)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
);

This behaviour is documented at
https://www.postgresql.org/docs/current/static/sql-createtable.html

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-03-22 15:23:11 Re: BUG #14597: Delay in query execution
Previous Message Tom Lane 2017-03-22 14:45:07 Re: BUG #14596: False primary/unique key constraint violations