From: Leif B. Kristensen <leif@solumslekt.org>
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
Message-ID: <200509211506.42862.leif@solumslekt.org> (raw)
In-Reply-To: <1127306186.20038.21.camel@Panoramix>
References: <1127306186.20038.21.camel@Panoramix>
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/
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: leif@solumslekt.org
Subject: Re: How to add column from old_table to new_table?
In-Reply-To: <200509211506.42862.leif@solumslekt.org>
* 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