Re: How to add column from old_table to new_table?

Поиск
Список
Период
Сортировка
От Leif B. Kristensen
Тема Re: How to add column from old_table to new_table?
Дата
Msg-id 200509211506.42862.leif@solumslekt.org
обсуждение исходный текст
Ответ на How to add column from old_table to new_table?  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
Список 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/


В списке pgsql-sql по дате отправления:

Предыдущее
От: Gnanavel S
Дата:
Сообщение: Re: How to add column from old_table to new_table?
Следующее
От: Joost Kraaijeveld
Дата:
Сообщение: Re: How to add column from old_table to new_table?