From: | "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to add column from old_table to new_table? |
Date: | 2005-09-21 13:06:42 |
Message-ID: | 200509211506.42862.leif@solumslekt.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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/
From | Date | Subject | |
---|---|---|---|
Next Message | Joost Kraaijeveld | 2005-09-21 13:09:36 | Re: How to add column from old_table to new_table? |
Previous Message | Gnanavel S | 2005-09-21 13:01:59 | Re: How to add column from old_table to new_table? |