Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 30F889F9EA1 for ; Thu, 27 Sep 2007 07:39:09 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 15052-06 for ; Thu, 27 Sep 2007 07:38:57 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.prosyst.com (ns.prosyst.com [195.14.248.50]) by postgresql.org (Postfix) with ESMTP id 2E2A39F99B3 for ; Thu, 27 Sep 2007 07:39:00 -0300 (ADT) Received: (qmail 29750 invoked from network); 27 Sep 2007 10:31:13 -0000 Received: from wizard.prosyst.com (HELO ?192.168.1.239?) (195.14.248.49) by mail.prosyst.com with (DHE-RSA-AES256-SHA encrypted) SMTP; 27 Sep 2007 10:31:13 -0000 Message-ID: <46FB880B.70003@prosyst.com> Date: Thu, 27 Sep 2007 12:38:03 +0200 From: Venelin Arnaudov User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Richard Huxton CC: pgsql-sql@postgresql.org Subject: Re: Problems with bulk update References: <46FB6822.9060507@prosyst.com> <46FB776D.5080406@archonet.com> In-Reply-To: <46FB776D.5080406@archonet.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200709/156 X-Sequence-Number: 29369 I have tried this gforge=> UPDATE data_table gforge-> SET field2_new=(SELECT new_id FROM mapping_table WHERE old_id= data_table.field2_old); and gforge-> update data_table set field2_new_=mt.new_id FROM data_table dt, mapping_table mt WHERE dt.field2_old=mt.old_id; but initially I got error. "ERROR: column data_table.old_brand_id does not exist" It took me an eternity to realize that it is because of a missing entry in the mapping table. I have added the record and the update run correctly. Thank you very much Kindest regards, Venelin Arnaudov Richard Huxton wrote: > Venelin Arnaudov wrote: >> Hi >> >> I want to update the values of one column of a table based on the >> matches in a second table > >> something like >> update table1 >> set table1.field2_new=table2.new_id >> from table2 >> where table1.field2_old=table2.old_id; > > Did you try it? > > http://www.postgresql.org/docs/8.2/static/sql-update.html > > PG has a non-standard "FROM" extension for just this purpose. >