Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooWJC-0000Ng-C6 for pgsql-admin@arkaria.postgresql.org; Fri, 28 Oct 2022 20:50:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ooWJA-0002uK-EF for pgsql-admin@arkaria.postgresql.org; Fri, 28 Oct 2022 20:50:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooWJA-0002uB-3q for pgsql-admin@lists.postgresql.org; Fri, 28 Oct 2022 20:50:28 +0000 Received: from mailout.easymail.ca ([64.68.200.34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooWJ7-0001FY-KJ for pgsql-admin@lists.postgresql.org; Fri, 28 Oct 2022 20:50:27 +0000 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id 97ED66646C; Fri, 28 Oct 2022 20:50:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at emo07-pco.easydns.vpn Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (emo07-pco.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wol6Ah4vSqtN; Fri, 28 Oct 2022 20:50:23 +0000 (UTC) Received: from smtpclient.apple (unknown [165.140.184.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailout.easymail.ca (Postfix) with ESMTPSA id 3213866464; Fri, 28 Oct 2022 20:50:23 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: Duplicate data even with primary keys enabled From: Scott Ribe In-Reply-To: Date: Fri, 28 Oct 2022 14:50:22 -0600 Cc: Holger Jakobs , pgsql-admin@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <59B1180A-4A4B-4A1A-B50A-C9D9B41AA67D@gmail.com> <74e777cb-c332-3db7-7c4a-784d408227d6@jakobs.com> <032E52B8-00C2-431D-BBAF-DCFCCEA817D2@elevated-dev.com> To: Teju Jakkidi vlogs X-Mailer: Apple Mail (2.3696.120.41.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Oct 28, 2022, at 2:42 PM, Teju Jakkidi vlogs = wrote: >=20 > 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=3D'3456' AND COL2=3D'76542' AND = COL3=3D'5'; >=20 > 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.