tinyBULK INSERT
ではないデータに対しては、これが正しいオプションであることに完全に同意します。ただし、デバッグ メッセージなどを 2 ~ 3 行追加する必要がある場合は、やり過ぎのようです。BULK INSERT
あなたの質問への答えはDBI::dbWriteTable()
関数です。以下の例 (R コードをAWS RDS
のインスタンスに接続していますMS SQL Express
):
library(DBI)
library(RJDBC)
library(tidyverse)
# Specify where you driver lives
drv <- JDBC(
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"c:/R/SQL/sqljdbc42.jar")
# Connect to AWS RDS instance
conn <- drv %>%
dbConnect(
host = "jdbc:sqlserver://xxx.ccgqenhjdi18.ap-southeast-2.rds.amazonaws.com",
user = "xxx",
password = "********",
port = 1433,
dbname= "qlik")
if(0) { # check what the conn object has access to
queryResults <- conn %>%
dbGetQuery("select * from information_schema.tables")
}
# Create test data
example_data <- data.frame(animal=c("dog", "cat", "sea cucumber", "sea urchin"),
feel=c("furry", "furry", "squishy", "spiny"),
weight=c(45, 8, 1.1, 0.8))
# Works in 20ms in my case
system.time(
conn %>% dbWriteTable(
"qlik.export.test",
example_data
)
)
# Let us see if we see the exported results
conn %>% dbGetQuery("select * FROM qlik.export.test")
# Let's clean the mess and force-close connection at the end of the process
conn %>% dbDisconnect()
転送される少量のデータに対してはかなり高速に動作し、必要に応じてかなりエレガントに見えますdata.frame
->SQL table
ソリューション。
楽しみ!