X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 94B7DD97D0 for ; Wed, 21 Sep 2005 10:06:51 -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 82625-06 for ; Wed, 21 Sep 2005 13:06:41 +0000 (GMT) Received: from mail58-s.fg.online.no (mail58-s.fg.online.no [148.122.161.58]) by svr1.postgresql.org (Postfix) with ESMTP id 5A0F3D97B4 for ; Wed, 21 Sep 2005 10:06:42 -0300 (ADT) Received: from [192.168.0.57] (062016183238.customer.alfanett.no [62.16.183.238]) by mail58.fg.online.no (8.12.11/8.12.11) with ESMTP id j8LD6hmE013395 for ; Wed, 21 Sep 2005 15:06:44 +0200 (MEST) From: "Leif B. Kristensen" To: pgsql-sql@postgresql.org Subject: Re: How to add column from old_table to new_table? Date: Wed, 21 Sep 2005 15:06:42 +0200 User-Agent: KMail/1.8.1 References: <1127306186.20038.21.camel@Panoramix> In-Reply-To: <1127306186.20038.21.camel@Panoramix> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509211506.42862.leif@solumslekt.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.08 required=5 tests=[AWL=0.080] X-Spam-Level: X-Archive-Number: 200509/183 X-Sequence-Number: 22730 On Wednesday 21 September 2005 14:36, Joost Kraaijeveld wrote: > Hi, > > I have an old_table with two columns: "id" and "old_attribute". I > have new table with the columns "id" and "new_attribute". > > old_table and new_table contain exactly the same id's. Now I want to > copy all the old_attribute from old_table to the corresponding > new_attribute in the new_table test=> create table old_table ( test(> old_table_id integer, test(> old_attribute char(1) test(> ); CREATE TABLE test=> create table new_table ( test(> new_table_id integer, test(> new_attribute char(1) test(> ); CREATE TABLE test=> insert into old_table values (1,'A'); INSERT 807376 1 test=> insert into old_table values (2,'B'); INSERT 807377 1 test=> insert into old_table values (3,'C'); INSERT 807378 1 test=> insert into new_table (new_table_id) values (1); INSERT 807379 1 test=> insert into new_table (new_table_id) values (2); INSERT 807380 1 test=> insert into new_table (new_table_id) values (3); INSERT 807381 1 test=> update new_table set new_attribute = test-> (select old_attribute from old_table test(> where old_table_id = new_table_id); UPDATE 3 test=> select * from new_table; new_table_id | new_attribute --------------+--------------- 1 | A 2 | B 3 | C (3 rader) -- Leif Biberg Kristensen http://solumslekt.org/