我有一个像
这样的CSV文件1,hello,13
2,world,14
3,ciao,26
我尝试使用CSVREAD
函数将此文件读入数据库,就像这样
insert into my_table( id, message, code ) values (
select convert( "id",bigint ), "message", convert( "code", bigint)
from CSVREAD( 'myfile.csv', 'id,message,code', null )
);
出于某种原因,我继续获得SQL error stating that the column count does not match.
该表是使用Hibernate / GORM创建的,包含我尝试插入的字段。
选择本身似乎有效,或者至少单独执行时不会导致任何错误。 我的陈述有什么问题?
答案 0 :(得分:11)
您已使用
insert into my_table(...) values (select ...)
但您应该使用SQL railroad diagrams中记录的
insert into my_table(...) select ...
实际上,对于H2,it is a bit faster if you create the table as follows,但我知道并非总是可行:
create table my_table(...) as select ...