Re: Duplicate data even with primary keys enabled

From: Scott Ribe <scott_ribe(at)elevated-dev(dot)com>
To: Teju Jakkidi vlogs <teja(dot)jakkidi05(at)gmail(dot)com>
Cc: Holger Jakobs <holger(at)jakobs(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Duplicate data even with primary keys enabled
Date: 2022-10-28 20:50:22
Message-ID: CECDAF83-106B-4425-865C-176B170CA56D@elevated-dev.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

> On Oct 28, 2022, at 2:42 PM, Teju Jakkidi vlogs <teja(dot)jakkidi05(at)gmail(dot)com> wrote:
>
> I am wondering how the query matters here?

Because it's possible to write a query that returns the same row multiple times.

> Also, I am just running a simple select from "TEST" with COL1, COL2, COL3 in the WHERE condition.
> select * from 'TEST" WHERE COL1='3456' AND COL2='76542' AND COL3='5';
>
> The actual Issue is I am unable to figure out why the table is having duplicate data in the primary key columns. Or how postgres accepted 2 rows with the same combination of the columns in the primary key constraint. I would expect it to throw primary key constraint violation error.

A corrupted index could allow that to happen by failing to catch the duplicate insert. I suppose it might also be able to cause the same row to be returned multiple times--although I have personally only ever seen corrupted indexes cause rows to not be found.

I'd suggest posting the result of \d "TEST", to make sure that the index hasn't been altered (or dropped), and trying REINDEX on the table as well.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Marco DE BOOIJ 2022-10-28 20:51:09 Re: Duplicate data even with primary keys enabled
Previous Message Teju Jakkidi vlogs 2022-10-28 20:42:06 Re: Duplicate data even with primary keys enabled