Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A2F1B1337BA1 for ; Fri, 8 Oct 2010 17:07:19 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 65963-05 for ; Fri, 8 Oct 2010 20:07:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by mail.postgresql.org (Postfix) with ESMTP id 0833D1337BA5 for ; Fri, 8 Oct 2010 17:07:12 -0300 (ADT) Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1P4JDi-0003ce-Mh; Fri, 08 Oct 2010 14:07:10 -0600 Received: from [208.187.158.94] (helo=[172.16.1.223]) by in01.mta.xmission.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1P4JDh-00018u-Lx; Fri, 08 Oct 2010 14:07:10 -0600 Message-ID: <4CAF79EB.1080606@gmail.com> Date: Fri, 08 Oct 2010 14:07:07 -0600 From: Rob Sargent User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100714 SUSE/3.0.6 Lightning/1.0b1 Thunderbird/3.0.6 MIME-Version: 1.0 To: pgsql-sql@postgresql.org References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-XM-SPF: eid=; ; ; mid=; ; ; hst=in01.mta.xmission.com; ; ; ip=208.187.158.94; ; ; frm=robjsargent@gmail.com; ; ; spf=neutral X-SA-Exim-Connect-IP: 208.187.158.94 X-SA-Exim-Mail-From: robjsargent@gmail.com X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;pgsql-sql@postgresql.org X-Spam-Relay-Country: Subject: Re: Duplicates Processing X-SA-Exim-Version: 4.2.1 (built Fri, 06 Aug 2010 16:31:04 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201010/21 X-Sequence-Number: 34672 On 10/08/2010 01:42 PM, Gary Chambers wrote: > Tim, > > Thanks for taking the time to reply! > >> | INSERT INTO substitutes ([...]) >> | SELECT [...] FROM >> | (SELECT *, >> | ROW_NUMBER() OVER (PARTITION BY wattage, tolerance, temperature >> | ORDER BY part_number) AS RN >> | FROM parts) AS SubQuery >> | WHERE RN > 1; > >> | DELETE FROM parts >> | WHERE primary_key IN >> | (SELECT primary_key FROM >> | (SELECT *, >> | ROW_NUMBER() OVER (PARTITION BY wattage, tolerance, temperature >> | ORDER BY part_number) AS RN >> | FROM parts) AS SubQuery >> | WHERE RN > 1); > > You have solved the problem precisely as I described it. In my haste > to make the request for assistance, I omitted one critical piece of > information that may call into question my data model. In its current > state, my substitute parts table contains only the part number (the > "new" one, so-to-speak), a foreign key reference to the original parts > table, and some location data (which is also in the original parts > table). Is there any advice you can offer in light of what I have > just described? I apologize for the oversight. > > -- Gary Chambers > Perhaps a trade off between nullable fields and redundant types. If your original table simply had a nullable column called isReplacementFor, into which you place in the subsequent rows the id of the first instance found.