Primary Key Update issue ?

From: Patrick FICHE <Patrick(dot)Fiche(at)aqsacom(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Primary Key Update issue ?
Date: 2019-09-06 09:06:04
Message-ID: VI1PR0501MB25747C214477E3CBD8102DFDEFBA0@VI1PR0501MB2574.eurprd05.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

While doing some testing on a Postgresql database, I encountered a strange behavior which is very simple to reproduce.
I just wanted to know if this is expected behavior or if it should be considered as an issue.

The scenario to reproduce it is the following.

CREATE TABLE Test ( pKey integer, Val integer, CONSTRAINT PK_Test PRIMARY Key( pKey ) );

INSERT INTO Test( pKey, Val ) VALUES ( 1, 1 );
INSERT INTO Test( pKey, Val ) VALUES ( 2, 2 );

UPDATE Test SET pKey = pKey + 1;

Here is the error that I get.

SQL Error [23505]: ERROR: duplicate key value violates unique constraint "pk_test"
Detail: Key (pkey)=(2) already exists.

I was expecting pKey to be incremented for each row, which would still respect the unique constraint....

I'm currently using PostgreSQL 11.5 but have the same problem on PostgreSQL 10.3 server.

Best Regards,

Patrick

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Joseph Krogh 2019-09-06 09:16:39 Sv: Primary Key Update issue ?
Previous Message Benoit Lobréau 2019-09-06 07:41:44 Re: PG11.2 - wal_level =minimal max_wal_senders = 0