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 4D822D978A for ; Wed, 21 Sep 2005 09:57:08 -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 81684-07 for ; Wed, 21 Sep 2005 12:57:01 +0000 (GMT) Received: from mail.rp-online.de (mail.rp-online.de [149.221.1.199]) by svr1.postgresql.org (Postfix) with ESMTP id A2B4AD97B1 for ; Wed, 21 Sep 2005 09:57:02 -0300 (ADT) Received: from mail1 (localhost [127.0.0.1]) by localhost.rp-online.de (Postfix) with SMTP id BF206202AF; Wed, 21 Sep 2005 14:57:05 +0200 (CEST) Received: from idefix.d.rp-online.de (idefix.d.rp-online.de [149.221.100.194]) by mail.rp-online.de (Postfix) with ESMTP id A03881FA8B; Wed, 21 Sep 2005 14:57:05 +0200 (CEST) From: Thomas Pundt Reply-To: Thomas Pundt Organization: RP Online Verlagsgesellschaft mbH To: pgsql-sql@postgresql.org, "Joost Kraaijeveld" Subject: Re: How to add column from old_table to new_table? Date: Wed, 21 Sep 2005 14:58:15 +0200 User-Agent: KMail/1.8.2 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-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509211458.15281.mlists@rp-online.de> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200509/181 X-Sequence-Number: 22728 Hi, On Wednesday 21 September 2005 14:36, Joost Kraaijeveld wrote: | Is that possible in a SQL script (pgadmin or psql console?) and if so, | what is the syntax in this example? funny that you mention pgadmin :-) | insert into new_table(new_attribute) | value( select old_attribute from old_table, new_table where old_table.id | = new_table_id) | where new_table.id = old_table.id from the pgadmin help system (reference|sql commands|insert): INSERT INTO table [ ( column [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | query } and some lines further an example: This example inserts some rows into table films from a table tmp_films with the same column layout as films: INSERT INTO films SELECT * FROM tmp_films WHERE date_prod < '2004-05-07'; Or - if I was misunderstanding your question and you simply want to update already existing rows in "new_table", you might try UPDATE new_table SET new_attribute = old_table.old_attribute FROM old_table WHERE new_table.id = old_table.id; Ciao, Thomas -- Thomas Pundt ---- http://rp-online.de/ ----