从Postgresql中的查询插入到表中

时间:2015-07-15 12:45:08

标签: sql postgresql

我有一张表Ty包含:

  a integer NOT NULL,
  b text,
  c text,
  d text,
  e text

我试图按照以下方式做出坚定的声明:

insert into Ty (b,c,d,e) values
                ('hello','world',select current_date,select name from users where userid=4)

但它不起作用。它说:

  

错误:语法错误在或附近"选择"

我读过的所有指南都说我可以在Insert中执行SQL语句,只要它们只返回一个值即可。那它为什么不起作用?

2 个答案:

答案 0 :(得分:2)

insert into Ty (b,c,d,e) 
select 'hello','world',current_date,name from users 
where userid=4

答案 1 :(得分:1)

insert into Ty (b,c,d,e)
SELECT 'hello','world',current_date, name from users where userid=4
相关问题