Re: How duplicate values inserted into the primary key column oftable and how to fix it - Mailing list pgsql-bugs

From Gavin Flower
Subject Re: How duplicate values inserted into the primary key column oftable and how to fix it
Date
Msg-id 00f48b5b-a5df-6aa2-bf70-d0166a3b1193@archidevsys.co.nz
Whole thread Raw
In response to Re: How duplicate values inserted into the primary key column oftable and how to fix it  (Patrick Headley <pheadley@linxco-inc.com>)
List pgsql-bugs
On 25/01/2019 09:28, Patrick Headley wrote:
>
> Sounds like you need a unique constraint on the PK field. The 
> duplicate values may be inserted if the sequence on the PK is out of 
> sync (if there is a sequence providing values for the PK).
>
> */Patrick Headley/*
> Linx Consulting, Inc.
> (303) 916-5522
> pheadley@linxco-inc.com
> www.linxco-inc.com
> On 1/24/19 8:30 AM, Adrian Klaver wrote:
>> On 1/24/19 4:46 AM, Raghavendra Rao J S V wrote:
>>> Hi All,
>>>
>>>
>>> We are using Postgresql 9.2 database.
>>>
>>> In one of the transactional table, I have observed duplicate values 
>>> for the primary key columns.
>>
>> Best guess a corrupted index. As Hellmuth said more information would 
>> be helpful.
>>
>>>
>>> Please guide me how is it possible and how to fix this kind of issue.
>>>
>>>
>>> -- 
>>> Regards,
>>> Raghavendra Rao J S V
>>>
>>
>>
A PRIMARY KEY, is by definition, UNIQUE!  Has been this way, as far back 
as I can remember!


 From https://www.postgresql.org/docs/11/sql-createtable.html
[...]
The PRIMARY KEY constraint specifies that a column or columns of a table 
can contain only unique (non-duplicate), nonnull values
[...]


http://www.postgresqltutorial.com/postgresql-primary-key/
[...]
Technically, a primary key constraint is the combination of a not-null 
constraint 
<http://www.postgresqltutorial.com/postgresql-not-null-constraint/> and 
a UNIQUE constraint 
<http://www.postgresqltutorial.com/postgresql-unique-constraint/>.
[...]



Cheers,
Gavin



pgsql-bugs by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: BUG #15597: possible bug in amcheck/amcheck_next (or corrupted index?)
Next
From: Bruce Momjian
Date:
Subject: Re: psql and readline comments