Re: BUG or strange behaviour of update on primary key

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: desmodemone <desmodemone(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, l(dot)denardo(at)miriade(dot)it, f(dot)dalmaso(at)miriade(dot)it
Subject: Re: BUG or strange behaviour of update on primary key
Date: 2011-10-17 22:59:16
Message-ID: 20984.1318892356@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message desmodemone 2011-10-17 23:30:49 Re: BUG or strange behaviour of update on primary key
Previous Message desmodemone 2011-10-17 22:09:35 BUG or strange behaviour of update on primary key