X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CD1E511F6774 for ; Fri, 7 Apr 2006 18:54:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78768-05 for ; Fri, 7 Apr 2006 18:54:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 11B4D11F676E for ; Fri, 7 Apr 2006 18:54:09 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k37Ls67g017021; Fri, 7 Apr 2006 17:54:06 -0400 (EDT) To: Bryce Nesbitt cc: pgsql-sql@postgresql.org Subject: Re: How to copy data between joined columns? In-reply-to: <4436DB41.2070303@obviously.com> References: <4436CC56.3040707@obviously.com> <1144442088.32269.31.camel@state.g2switchworks.com> <4436DB41.2070303@obviously.com> Comments: In-reply-to Bryce Nesbitt message dated "Fri, 07 Apr 2006 14:36:01 -0700" Date: Fri, 07 Apr 2006 17:54:06 -0400 Message-ID: <17020.1144446846@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.13 required=5 tests=[AWL=0.130] X-Spam-Score: 0.13 X-Spam-Level: X-Archive-Number: 200604/56 X-Sequence-Number: 24865 Bryce Nesbitt writes: > If it were for the same rows in the same table, I would not have asked. > This is for columns from two tables, whos relationship is only > meaningful after a join. You have to write out the join condition longhand, eg UPDATE targettable SET targcol = srccol FROM srctable WHERE joincol1 = joincol2; This can be tricky, particularly if there might be more than one source row joining to a given target row. (IIRC, the effective behavior is that any given target row's update will occur against a random one of the possible join partners.) A lot of people prefer to code it using sub-selects. regards, tom lane