简体   繁体   English

R中批量/批量插入

[英]Batch / Bulk insert in R

I am trying to do a batch insert in R using RJDBC. 我正在尝试使用RJDBC在R中进行批量插入。 It seems like it inserts 1 row at a time which takes a lot of time. 看起来它一次插入一行需要花费很多时间。

I was wondering if anyone knows of a solution in R to do bulk insert data from R to SQL. 我想知道是否有人知道R中的解决方案从R到SQL批量插入数据。 I know RODBC can do parametrized insert which is fast but not as fast as bulk insert. 我知道RODBC可以进行参数化插入,这种插入很快但不如批量插入快。

I don't know about your "R" language, but there is a BULK sql statement available in sqlExe. 我不知道你的“R”语言,但是在sqlExe中有一个BULK sql语句。

sqlExe is a utility that connects to SQL databases via ODBC and will execute any valid SQL, plus it has some additional features ( http://sourceforge.net/projects/sqlexe/ ) sqlExe是一个通过ODBC连接到SQL数据库的实用程序,它将执行任何有效的SQL,还有一些附加功能( http://sourceforge.net/projects/sqlexe/

For example, assuming the target table is: 例如,假设目标表是:

 table: [mydata]
 -------------------
 row_id      char(1)
 row_idx     integer
 row_desc    char(32)

To do your insert task with sqlExe you would prepare a file with your input: 要使用sqlExe执行插入任务,您需要使用输入准备一个文件:

  input.dat

    a,1,this is row 1
    b,2,this is row 2
    c,3,this is row 3
    d,4,this is row 4

The command line to import: 要导入的命令行:

  sql --dsn MYDB -e "BULK INSERT input.dat, INSERT INTO mydata(row_id,row_idx,row_desc) VALUES(?,?,?)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM