Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 61EEA2E0095 for ; Thu, 20 Mar 2008 10:06:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 03269-01 for ; Thu, 20 Mar 2008 10:06:44 -0300 (ADT) X-Greylist: delayed 00:55:39.650782 by SQLgrey-1.7.5 Received: from vms173001pub.verizon.net (vms173001pub.verizon.net [206.46.173.1]) by postgresql.org (Postfix) with ESMTP id C74B32E009D for ; Thu, 20 Mar 2008 10:06:52 -0300 (ADT) Received: from [192.168.2.5] ([96.228.149.47]) by vms173001.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JY100J0T2MX2TX0@vms173001.mailsrvcs.net> for pgsql-sql@postgresql.org; Thu, 20 Mar 2008 06:59:21 -0500 (CDT) Date: Thu, 20 Mar 2008 08:10:47 -0400 From: Joe Subject: Re: Select into In-reply-to: <786D2B38-CE0A-41BF-9E70-4DEB22F8D9EF@eclinic.com.au> To: Gavin 'Beau' Baumanis Cc: pgsql-sql@postgresql.org Message-id: <47E25447.6040109@freedomcircle.net> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit References: <94F93C0F-DA95-4435-B253-57C90961DF34@eclinic.com.au> <20080320104922.GB18935@a-kretschmer.de> <65937bea0803200358i290bdc87hdeca777b593b5df1@mail.gmail.com> <786D2B38-CE0A-41BF-9E70-4DEB22F8D9EF@eclinic.com.au> User-Agent: Thunderbird 1.5.0.9 (X11/20080117) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/142 X-Sequence-Number: 30470 Gavin 'Beau' Baumanis wrote: > > The copy is inside the same table, so I don't understand why it (the > required query ) would require any joins. > > Ie. I want to copy the contents of a row (but for the id column - of > course) into a record in the same table. I think what you want is something like this: Given (col1 being the id or PK): col1 | col2 | col3 ------+------+--------------- 1 | 123 | first record 2 | 456 | second record 3 | 789 | third record then update t1 set col2 = t1copy.col2, col3 = t1copy.col3 from t1 as t1copy where t1.col1 = 1 and t1copy.col1 = 3; will result in: col1 | col2 | col3 ------+------+--------------- 1 | 789 | third record 2 | 456 | second record 3 | 789 | third record So, it is a join ... of a table with a virtual copy of itself. Joe