desmodemone <desmodemone(at)gmail(dot)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