X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A157F329D22 for ; Fri, 22 Oct 2004 06:11:10 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85729-10 for ; Fri, 22 Oct 2004 05:11:03 +0000 (GMT) Received: from screen.dri.edu (screen.dri.edu [134.197.100.251]) by svr1.postgresql.org (Postfix) with ESMTP id 3885C32AFEE for ; Fri, 22 Oct 2004 06:11:04 +0100 (BST) Received: (from fw_mx@localhost) by screen.dri.edu (8.9.1b+Sun/8.9.1) id QAA07424 for ; Thu, 21 Oct 2004 16:11:59 -0700 (PDT) Received: from derringer.dri.edu( 10.10.9.111) by screen.dri.edu via smap (V2.1.dri) id xma007422; Thu, 21 Oct 04 16:11:57 -0700 Received: from dri.edu (ppp16.dri.edu [10.10.8.216]) by derringer.dri.edu (8.9.3+Sun/8.9.1) with ESMTP id QAA17861; Thu, 21 Oct 2004 16:10:56 -0700 (PDT) Message-ID: <417843C8.6060406@dri.edu> Date: Thu, 21 Oct 2004 16:18:32 -0700 From: lorid User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7a) Gecko/20040219 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kent Anderson Cc: "Pgsql-Sql@Postgresql. Org" Subject: Re: Finding duplicated values References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------000104040401020407000003" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.4 tagged_above=0.0 required=5.0 tests=HTML_30_40, HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: * X-Archive-Number: 200410/158 X-Sequence-Number: 19261 This is a multi-part message in MIME format. --------------000104040401020407000003 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Kent Anderson wrote: > I have a few tables that have duplicated values from an import from a > different database. I have two keys I tried to set as primary and got > an error > ERROR: could not create unique index > DETAIL: Table contains duplicated values. > > Is there some join I can use to compare the hmhmkey, wmwmkey pairs > against the table to find duplicate values? Each pair key should be > unique but the old database was less than normalized. > > I was trying to use the code below but it returned no rows. > > SELECT hmhmkey, wmwmkey > FROM exceptions > EXCEPT > SELECT hmhmkey, wmwmkey > FROM exceptions; > > Any suggestions? > > Kent Anderson > EZYield.com > 407-629-0900 > www.ezyield.com > > ======================================== > This electronic message transmission contains information from the > Company that may be proprietary, confidential and/or privileged. The > information is intended only for the use of the individual(s) or > entity named above. If you are not the intended recipient, be aware > that any disclosure, copying or distribution or use of the contents of > this information is prohibited. If you have received this electronic > transmission in error, please notify the sender immediately by > replying to the address listed in the "From:" field. > ****************************** This might do it... If you do this on the table that had duplicates you wont need to join select count(hmhmkey),count(wmwmkey) from exceptions group by hmhmkey,wmwmkey having count(hmhmkey) >1 or having count(wmwmkey) >1; --------------000104040401020407000003 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Kent Anderson wrote:
I have a few tables that have duplicated values from an import from a different database. I have two keys I tried to set as primary and got an error
ERROR:  could not create unique index
DETAIL:  Table contains duplicated values.
 
Is there some join I can use to compare the hmhmkey, wmwmkey pairs against the table to find duplicate values? Each pair key should be unique but the old database was less than normalized.
 
I was trying to use the code below but it returned no rows.
 
SELECT hmhmkey, wmwmkey
FROM   exceptions
EXCEPT
SELECT hmhmkey, wmwmkey
FROM  exceptions;
 
Any suggestions?
 
Kent Anderson
EZYield.com
407-629-0900
 
========================================
This electronic message transmission contains information from the Company that may be proprietary, confidential and/or privileged. The information is intended only for the use of the individual(s) or entity named above.  If you are not the intended recipient, be aware that any disclosure, copying or distribution or use of the contents of this information is prohibited.  If you have received this electronic transmission in error, please notify the sender immediately by replying to the address listed in the "From:" field.
 
******************************
This might do it...
If you do this on the table that had duplicates you wont need to join
select count(hmhmkey),count(wmwmkey) from
exceptions group by hmhmkey,wmwmkey having count(hmhmkey) >1 or having count(wmwmkey) >1; 


--------------000104040401020407000003--