【发布时间】:2011-04-20 01:37:02
【问题描述】:
我有一个包含 2 列的表 (table2):姓名和年龄。 我有另一个表 (table1),其中包含列名称、年龄、值、类型。
我想通过添加 table2 值和 value=1 和 type="abc" 来更新 table1。
我试过了:
方法一:
insert into table1(select * from table2), 1, 'abc';
但是在 1 之前的 ',' 处出现错误,表示子查询不能返回多于一列。
方法二:
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 有效,但我猜这不是有效的方法。
【问题讨论】:
-
在询问之前在 stackoverflow 中搜索答案。希望这个问题能解决你的问题:stackoverflow.com/questions/3736732/…
标签: postgresql