我有一個包含2列的表(table2):名稱和年齡。 我有另一個表(table1)與列名稱,年齡,價值,類型。Postgresql子查詢獲取多行
我想更新table1添加table2值和值= 1和type =「abc」。
我想:
方法1:在
insert into table1(select * from table2), 1, 'abc';
但是,得到錯誤 '' 1日前,說子查詢不能返回多個列。
方法2:
CREATE TABLE table2
(
name varchar(20),
age varchar(20)
);
insert into table2 .... inserted some values
alter table table2 add "value" varchar(10);
alter table table2 add "name" varchar(20);
update table2 set value=1, name='abc';
insert into table1 select * from table2;
我使用PostgreSQL。任何人都可以幫助我解決這個問題。方法2的作品,但這不是有效的方式,我猜。
在提問之前在計算器中搜索答案。希望這個問題解決你的問題:http://stackoverflow.com/questions/3736732/update-or-insert-multiple-rows-and-cols-from-subquery-in-postgresql – Senthil 2011-04-20 02:09:22