Re: BUG or strange behaviour of update on primary key - Mailing list pgsql-hackers

From Tom Lane
Subject Re: BUG or strange behaviour of update on primary key
Date
Msg-id 20984.1318892356@sss.pgh.pa.us
Whole thread Raw
In response to BUG or strange behaviour of update on primary key  (desmodemone <desmodemone@gmail.com>)
Responses Re: BUG or strange behaviour of update on primary key  (desmodemone <desmodemone@gmail.com>)
List pgsql-hackers
desmodemone <desmodemone@gmail.com> writes:
> create table testup ( a int ) ;

> alter table testup add primary key (a ) ;

> insert into testup values (1);

> insert into testup values (2);

>  update  testup set a=a+1 ;
> ERROR:  duplicate key value violates unique constraint "testup_pkey"
> DETTAGLI: Key (a)=(2) already exists.

If you want that to work reliably, you need to mark the primary key
constraint as deferred.  By default, uniqueness is checked immediately
when a row is inserted or updated --- and here, when you update 1 to 2,
it's not unique because the second row hasn't been visited yet.
        regards, tom lane


pgsql-hackers by date:

Previous
From: desmodemone
Date:
Subject: BUG or strange behaviour of update on primary key
Next
From: desmodemone
Date:
Subject: Re: BUG or strange behaviour of update on primary key