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 929EED97A5 for ; Wed, 21 Sep 2005 09:56:19 -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 80753-07 for ; Wed, 21 Sep 2005 12:56:09 +0000 (GMT) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by svr1.postgresql.org (Postfix) with ESMTP id B6204D9780 for ; Wed, 21 Sep 2005 09:56:10 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de with ESMTP (Nemesis), id 0MKxQS-1EI48z03z3-0005GU; Wed, 21 Sep 2005 14:56:13 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1EI49B-0005n5-00 for pgsql-sql@postgresql.org; Wed, 21 Sep 2005 14:56:25 +0200 Date: Wed, 21 Sep 2005 14:56:25 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: How to add column from old_table to new_table? Message-ID: <20050921125625.GB21483@webserv.wug-glas.de> Mail-Followup-To: "A. Kretschmer" , pgsql-sql@postgresql.org References: <1127306186.20038.21.camel@Panoramix> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1127306186.20038.21.camel@Panoramix> X-DEST: 208 X-MSMail-Priority: High X-Message-Flag: Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) X-OS: Linux - weil ich es mir Wert bin! X-Info: registrierter Linux-User 97922 http://counter.li.org User-Agent: mutt-ng 1.5.9i (Linux) X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.291 required=5 tests=[AWL=0.024, MISSING_MIMEOLE=0, X_MSMAIL_PRIORITY_HIGH=0.267] X-Spam-Level: X-Archive-Number: 200509/180 X-Sequence-Number: 22727 am 21.09.2005, um 14:36:26 +0200 mailte Joost Kraaijeveld folgendes: > Hi, > > I have an old_table with two columns: "id" and "old_attribute". I have > new table with the columns "id" and "new_attribute". There are indexes on id? > Is that possible in a SQL script (pgadmin or psql console?) and if so, > what is the syntax in this example? Yes, of course. > > I have tried something as: > > 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 Error, because i don't need a insert on new_table. You need a update! (If there a primary index on id this will raise a error) update t_new set name = (select name from t_old) where t_old.id=t_new.id; (t_old and t_new are the tables with (id, name) similar your example) Regards, Andreas -- Andreas Kretschmer (Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net === Schollglas Unternehmensgruppe ===