我正在尝试将使用MATLAB创建的大约8000万条记录插入到Vertica数据库表中。我想知道我们是否可以使用COPY LOCAL
在MATLAB中调用exec(conn, sql)
语句作为常规sql语句。出于测试目的,我尝试使用具有大约400万条记录的dat文件,如下所示:
sqlstmnt = 'COPY schema.table_name (FK_CUSTOMER_ID,FK_RUN_START_DATE_ID,FK_RUN_END_DATE_ID,FK_TRAVEL_ID,FK_ORIGIN_ID,FK_DEST_ID,FK_SEGMENT_ID,SEGMENT_PERCENTAGE,LAST_UPDATED) FROM LOCAL ''/my/file/full/path/test1.dat''';
results = exec(conn,sqlstmnt);
但它在results.Message
中给出了错误:
[Vertica] JDBC期望ResultSet但不是从查询“COPY schema.table_name(FK_CUSTOMER_ID,FK_RUN_START_DATE_ID,FK_RUN_END_DATE_ID,FK_TRAVEL_ID,FK_ORIGIN_ID,FK_DEST_ID,FK_SEGMENT_ID,SEGMENT_PERCENTAGE,LAST_UPDATED)FROM LOCAL'/ my / file / full /生成的路径/ test1.dat'”。查询未执行。
我在'.dat'文件中的数据按照COPY LOCAL
中提到的列的顺序排列。
我找不到任何有用的资源来解释此错误。
我有这个test1.dat文件,我可以使用来自vsql的COPY插入但由于我在MATLAB中运行我的代码有很多次迭代,每次迭代产生大约一百万条记录,我想在每次迭代时插入它们。任何帮助都会非常棒。
答案 0 :(得分:0)
COPY命令返回包含已加载数据量的ResultSet,我看到两个主要选项
1)results = exec(conn,sqlstmnt);
2)results = runsqlscript(conn,'nameOfSQLScriptthatIncludeTheCopyCommand.sql')
我希望你会发现它很有用
谢谢
答案 1 :(得分:0)
我刚刚审核完您的输入样本数据。 我看到输入csv到目标表的映射存在的主要问题。
Main issues are :
1) Lines are broken into 2 lines ( you should prefer having one sample per line and avoid brock it into 2 lines )
Eg : "1,20150101,0,2,2573,2714,1,8.147237e-01
50,48,49,54,45,48,51,-28 12:11:46"
2) when you define data types on vertica table ,eg: timestamp the data on the csv must reflect to it ( what you have is "-28 12:11:46" , this will not work )
After you fix all this issues , make sure you test it using vsql , then go and try it with matlab
I hope you will find it useful.