多个选择插入

时间:2012-05-13 03:44:59

标签: sql database postgresql

我需要能够为插入设置多个select语句或值。如果我删除第二列名称(notication_timestamp),以下工作。

insert into notification (msg,notification_timestamp) select msg from data;

我希望能够说:

insert into notification (msg,notification_timestamp) values (select msg from data,now());

但这不起作用。有什么想法吗?

2 个答案:

答案 0 :(得分:5)

删除values语句:

Insert into notification(msg, notification_timestamp)
    Select msg, now()
    from data

答案 1 :(得分:2)

您没有将notification_timestamp放在选择查询

insert into notification (msg,notification_timestamp) select msg,'value for notification_timestamp' from data;

所以可能

insert into notification (msg,notification_timestamp) select msg,now() from data;