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 B95A7D1B191 for ; Tue, 22 Jun 2004 16:48:07 -0300 (ADT) 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 50207-04 for ; Tue, 22 Jun 2004 19:48:04 +0000 (GMT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id C7904D1B3A8 for ; Tue, 22 Jun 2004 16:47:59 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 1BcrFO-000HVs-0V; Tue, 22 Jun 2004 20:47:59 +0100 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 89DD116E1A; Tue, 22 Jun 2004 20:47:57 +0100 (BST) Message-ID: <40D88CED.50903@archonet.com> Date: Tue, 22 Jun 2004 20:47:57 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bruno Wolff III Cc: Matthew Nuzum , pgsql-sql@postgresql.org Subject: Re: matching rows differing only by fkey,pkey References: <20040622172704.GA19163@wolff.to> <200406221740.i5MHe6nb015623@ms-smtp-02.tampabay.rr.com> <20040622181649.GB20086@wolff.to> In-Reply-To: <20040622181649.GB20086@wolff.to> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/211 X-Sequence-Number: 18156 Bruno Wolff III wrote: > On Tue, Jun 22, 2004 at 13:40:03 -0400, > Matthew Nuzum wrote: > >> The end result is to duplicate the data for a particular record in table >> "a" so that all of it's related data in tables "b" and "c" is duplicated. >>Where "b" is the middle table in a many to many relationship. For example, >> >>- a ---- - b ---- - c ---- >> aid <--+ bid <--+ cid >> data1 +-->aid +-->bid >> data2 field1 info1 >> date3 field2 info2 >> >>SELECT a.*,b.*,c.* from a,b,c where b.aid = a.aid and c.bid = b.bid; >> >>So, the goal is to duplicate an object that is made up of the data stored >>across these three tables. [snip] > Offhand I can't think of a way to avoid using a procedural language to walk > through the b table so that you can easily keep track of which new bid > corresponds to which old bid. However, writing a perl script or plsql > function to do this for you shouldn't be difficult. Screams out plpgsql to me - it's good at automating what is basically cut & paste of values. -- Richard Huxton Archonet Ltd