【发布时间】:2013-01-15 11:01:30
【问题描述】:
我已经创建了一个包含数据的表,我想添加更多行。 如果我执行以下操作,这些行确实会完美显示:
select elem_1, elem_2, 'myTag' as source, count(*) as tally
from origin_table group by elem_1, elem_2;
我所做的基本上是从 origin_table 中获取数据,并通过 elem_1 和 elem_2 进行选择,我将标签“myTag”附加到这些对中的每一对。由于我可能有重复项,因此我也将 count(*) 视为计数,以知道我在 origin_table 中有多个相等的条目。这是一个可以避免的细节。
现在,如果我继续做广告,请执行以下操作:
insert in to destination_table
select elem_1, elem_2, 'myTag' as source, count(*) as tally
from origin_table group by elem_1, elem_2;
postgres 吠声:
ERROR: invalid input syntax for integer: "myTag"
LINE 1: insert into destination_table select elem_1, elem_2, 'myTag' as sou...
我明白,但我不喜欢,因为我不知道如何克服它。
那么,我该怎么做呢?
谢谢!
【问题讨论】:
-
你写的像
in to,真的吗? (应该是INTO)。 -
强烈建议您在插入语句 (
insert into destination_table (col1, col2, col3) ...) 中列出列以避免出现问题。如果这是您的问题的原因,我不会感到惊讶 -
@Anton:嗯。不,我和其他人一样写 INTO,但有时我忘记正确输入:)
-
@horse:马上试试。这是我应该遵循的好习惯。
标签: postgresql select insert