Created
May 9, 2014 20:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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