Skip to content

Instantly share code, notes, and snippets.

@billinkc
Created May 9, 2014 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billinkc/70f1d64418e7dd813f02 to your computer and use it in GitHub Desktop.
Save billinkc/70f1d64418e7dd813f02 to your computer and use it in GitHub Desktop.
POC for testing the fastest way to push an R data from into SQL Server
# http://www.r-tutor.com/r-introduction/data-frame
# http://stackoverflow.com/questions/23572621/what-is-the-fastest-way-to-write-to-a-db-table-from-r
# http://www.statmethods.net/input/dbinterface.html
library(RODBC)
myconn64 <-odbcConnect("RM_ODBC_64", "", "")
src <- sqlQuery(myconn64, "SELECT T.* FROM sys.tables AS T CROSS APPLY (SELECT 1 FROM sys.all_columns) AS AC(x);")
#Create target table
cmd <- sqlQuery(myconn64, "IF NOT EXISTS(SELECT 1 FROM sys.tables T WHERE T.name ='r_table' AND t.schema_id = SCHEMA_ID('dbo'))
BEGIN
SELECT * INTO dbo.r_table FROM sys.tables AS T WHERE NULL = 1;
END
")
# Error: could not find function "dbWriteTable"
dbWriteTable(myconn64,"dbo.r_table", src)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment