Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id AF28A2E00C4 for ; Thu, 20 Mar 2008 09:05:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 19803-06 for ; Thu, 20 Mar 2008 09:05:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by postgresql.org (Postfix) with ESMTP id 0DA752E00C9 for ; Thu, 20 Mar 2008 09:05:23 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id 47DF65B7; Thu, 20 Mar 2008 21:05:18 +0900 (WST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id E203A1E0435; Thu, 20 Mar 2008 21:05:18 +0900 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 4Xes1u6aCWZ8; Thu, 20 Mar 2008 21:05:18 +0900 (WST) Received: from [192.168.3.189] (unknown [192.168.3.189]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTP id 2172A1E0434; Thu, 20 Mar 2008 21:05:18 +0900 (WST) Message-ID: <47E252F8.6030008@postnewspapers.com.au> Date: Thu, 20 Mar 2008 21:05:12 +0900 From: Craig Ringer User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Gavin 'Beau' Baumanis Cc: Gurjeet Singh , pgsql-sql@postgresql.org, "A. Kretschmer" Subject: Re: Select into 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> In-Reply-To: <786D2B38-CE0A-41BF-9E70-4DEB22F8D9EF@eclinic.com.au> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/138 X-Sequence-Number: 30466 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. Maybe you should use FROM clause in the update that references a row-valued subquery? craig=# create table x ( id serial, val integer ); NOTICE: CREATE TABLE will create implicit sequence "x_id_seq" for serial column "x.id" CREATE TABLE craig=# insert into x ( val ) values ( 4 ) , ( 6 ) ; INSERT 0 2 craig=# select * from x; id | val ----+----- 1 | 4 2 | 6 (2 rows) craig=# update x set val = foundrow.val from ( select val from x where id = 2 ) as foundrow where id = 1 ; UPDATE 1 craig=# select * from x; id | val ----+----- 2 | 6 1 | 6 (2 rows) craig=# insert into x ( val ) select generate_series(0,10000); INSERT 0 10001 craig=# explain update x set val = foundrow.val from ( select val from x where id = 4123 ) as foundrow where id = 5912 ; QUERY PLAN ------------------------------------------------------------------------- Nested Loop (cost=0.00..16.55 rows=1 width=14) -> Index Scan using x_id_idx on x (cost=0.00..8.27 rows=1 width=10) Index Cond: (id = 5912) -> Index Scan using x_id_idx on x (cost=0.00..8.27 rows=1 width=4) Index Cond: (public.x.id = 4123) (5 rows) Will that do the job? -- Craig Ringer