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

Started by Raghavendra Rao J S Vabout 7 years ago5 messagesbugsgeneral
Jump to latest
#1Raghavendra Rao J S V
raghavendrajsv@gmail.com
bugsgeneral

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.

Please guide me how is it possible and how to fix this kind of issue.

--
Regards,
Raghavendra Rao J S V

#2Hellmuth Vargas
hivs77@gmail.com
In reply to: Raghavendra Rao J S V (#1)
bugsgeneral
Re: How duplicate values inserted into the primary key column of table and how to fix it

Hi
you could provide the definition of the table that includes the definition
of the primary key?

El jue., 24 de ene. de 2019 a la(s) 09:18, Raghavendra Rao J S V (
raghavendrajsv@gmail.com) escribió:

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.

Please guide me how is it possible and how to fix this kind of issue.

--
Regards,
Raghavendra Rao J S V

--
Cordialmente,

Ing. Hellmuth I. Vargas S.

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Raghavendra Rao J S V (#1)
bugsgeneral
Re: How duplicate values inserted into the primary key column of table and how to fix it

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

--
Adrian Klaver
adrian.klaver@aklaver.com

#4Patrick Headley
pheadley@linxco-inc.com
In reply to: Adrian Klaver (#3)
bugsgeneral
Re: How duplicate values inserted into the primary key column of table and how to fix it

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

Show quoted text

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

#5Gavin Flower
GavinFlower@archidevsys.co.nz
In reply to: Patrick Headley (#4)
bugsgeneral
Re: How duplicate values inserted into the primary key column of table and how to fix it

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/&gt; and
a UNIQUE constraint
<http://www.postgresqltutorial.com/postgresql-unique-constraint/&gt;.
[...]

Cheers,
Gavin