Re: How duplicate values inserted into the primary key column of table and how to fix it

From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
To: pheadley(at)linxco-inc(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: How duplicate values inserted into the primary key column of table and how to fix it
Date: 2019-01-25 23:27:15
Message-ID: 00f48b5b-a5df-6aa2-bf70-d0166a3b1193@archidevsys.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

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(at)linxco-inc(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2019-01-26 00:18:01 Re: psql and readline comments
Previous Message Peter Geoghegan 2019-01-25 17:57:59 Re: BUG #15597: possible bug in amcheck/amcheck_next (or corrupted index?)

Browse pgsql-general by date

  From Date Subject
Next Message Chuck Martin 2019-01-26 23:04:23 Query help
Previous Message Adrian Klaver 2019-01-25 20:28:06 Re: RES: Postgresql Crasching