From: A. Kretschmer <akretschmer@despammed.com>
To: pgsql-sql@postgresql.org
Subject: Re: How to add column from old_table to new_table?
Date: Wed, 21 Sep 2005 14:56:25 +0200
Message-ID: <20050921125625.GB21483@webserv.wug-glas.de> (raw)
In-Reply-To: <1127306186.20038.21.camel@Panoramix>
References: <1127306186.20038.21.camel@Panoramix>
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 ===
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: akretschmer@despammed.com
Subject: Re: How to add column from old_table to new_table?
In-Reply-To: <20050921125625.GB21483@webserv.wug-glas.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox