H2数据库,通过从CSVREAD中选择结果来插入

时间:2013-10-10 15:10:03

标签: sql csv h2

我有一个像

这样的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创建的,包含我尝试插入的字段。

选择本身似乎有效,或者至少单独执行时不会导致任何错误。 我的陈述有什么问题?

1 个答案:

答案 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 ...