rodbc

How can we bulk insert data in SQLServer without creating a text file from RODBC package?

痞子三分冷 提交于 2019-12-24 01:24:07
问题 This question is the extension of this question How to quickly export data from R to SQL Server. Currently I am using following code: # DB Handle for config file # dbhandle <- odbcDriverConnect() # save the data in the table finally sqlSave(dbhandle, bp, "FACT_OP", append=TRUE, rownames=FALSE, verbose = verbose, fast = TRUE) # varTypes <- c(Date="datetime", QueryDate = "datetime") # sqlSave(dbhandle, bp, "FACT_OP", rownames=FALSE,verbose = TRUE, fast = TRUE, varTypes=varTypes) # DB handle

How to save R plot image to database?

穿精又带淫゛_ 提交于 2019-12-24 00:54:10
问题 I'd like to save a plot image directly to the database. Is the best way in R to do this: Write the plot image (png) to the filesystem Read the file that was written Send the file to the database via query (RODBC) Ideally I'd like to combine steps 1 and 2 above by simply write the png image to a binary connection. Does R support this? 回答1: No, the graphics devices are file-based, so your steps 1-3 are correct. You need a fourth to unlink the temporary file but that is about it. 回答2: If you use

RODBC pulling float as character in SQL Server

我与影子孤独终老i 提交于 2019-12-23 16:02:11
问题 I have searched quite a bit and read the package documentation, but can't find a solution for this. I'm using RODBC 1.3-12 against Microsoft SQL Server with the below details. DBMS_Name "Microsoft SQL Server" DBMS_Ver "10.50.6220" Driver_ODBC_Ver "03.52" Driver_Name "SQLSRV32.DLL" Driver_Ver "06.01.7601" ODBC_Ver "03.80.0000" I'm not sure how to give a reproducable example, since you'd need a DB, but below is code similar to what I'm using. myConnection<- odbcDriverConnect(connection =

How to skip primary key in sqlSave() command?

我是研究僧i 提交于 2019-12-23 12:48:11
问题 I am trying to insert a data.frame in the MySQL database using RODBC. The command I am using is the following: sqlSave(channel,dbData,tablename='table_name', append=TRUE,safer=TRUE,fast=FALSE,verbose=TRUE) Now the table in which I am trying to insert the data has a primary key which is auto-increment. My table has total of 7 columns including the primary key. In my data frame, I have 6 columns because I don't want to insert the PK myself. However when I run the command, I get the following

How to append data to a SQL Server table with IDENTITY primary key using function sqlSave() in R?

醉酒当歌 提交于 2019-12-23 11:46:46
问题 I created a table in SQL Server as follows: CREATE TABLE testPK ( ID INT NOT NULL IDENTITY (1, 1) PRIMARY KEY, NumVal NUMERIC (18, 4) ) Now I want to append data to testPK from an R program using the RODBC function sqlSave() as follows: # Specify data to append test.dt <- data.table(NumVal = 1.0) # Assign connection myconn <- odbcDriverConnect(connectionString) # Append test.dt to SQL table testPK sqlSave(channel = myconn, dat = test.dt, tablename = 'testPK', rownames = FALSE, append = TRUE)

How to use RODBC to save dataframe to table with primary key generated at database

无人久伴 提交于 2019-12-23 09:49:56
问题 I would like to enter a data frame into an existing table in a database using an R script, and I want the table in the database to have a sequential primary key. My problem is that RODBC doesn't seem to allow the primary key constraint. Here's the SQL for creating the table I want: CREATE TABLE [dbo].[results] ( [ID] INT IDENTITY (1, 1) NOT NULL, [FirstName] VARCHAR (255) NULL, [LastName] VARCHAR (255) NULL, [Birthday] DATETIME NULL, [CreateDate] DATETIME NULL, CONSTRAINT [PK_dbo.results]

RODBC ERROR: Could not SQLExecDirect 'CREATE TABLE … when doing sqlSave

橙三吉。 提交于 2019-12-23 04:34:27
问题 Here is the short story, and it is important to talk about the setup, I’m using RODBC and FreeTDS to connect to the SQL Azure database. Remember it is SQL Azure database (also happen to be issue for on premise SQL Server, that alarm me to post it here to ask for help or understand the real issue). First, it does not play nice with the database without a cluster key, or a key, so what need to do is addPK = T or longer version addPK = TRUE Solution #1. two steps approach This will help create

Extracting Table from HANA using R

帅比萌擦擦* 提交于 2019-12-23 04:26:40
问题 This is the table I am trying to grab. From my HANA Database however I keep getting the below error. I know the table exists as I have pulled it in from Qlikview. From Qlikview I pull in the table using the below syntax "_MY_SCHEMA_"."My.Table.Name/Table_ONE" When I try to do the same thing in R using I use the following to grab the same table mydate <- sqlFetch(myconn, "_MY_SCHEMA.My.Table.Name/Table_ONE") This is the error that I get Error in odbcTableExists(channel, sqtable) : table not

Parameterize SQL Queries using R RODBC

≯℡__Kan透↙ 提交于 2019-12-23 02:43:07
问题 I have a rather simple question. On a daily basis, I perform data analysis in R using the RODBC package. I connect it to our data warehouse using SQL and move it into the R environment dbhandle <- odbcDriverConnect('driver={SQL Server};server=SQLSERVER;database=MYDATABASE;trusted_connection=true') degrees <- sqlQuery(dbhandle, "select Inst, ID, DegreeDate, Degree from DEGREE where FY = ('2015') group by Inst, ID, DegreeDate, Degree order by Inst, ID, DegreeDate, Degree", as.is=TRUE) You know

Efficient way to insert data frame from R to SQL

丶灬走出姿态 提交于 2019-12-21 17:33:43
问题 I have a data frame with 10 million rows and 5 columns that I want to insert to an existing sql table. Note that I do not have permission to create a table, I can only insert values into an existing table. I'm currently using RODBCext query_ch <- "insert into [blah].[dbo].[blahblah] (col1, col2, col3, col4, col5) values (?,?,?,?,?)" sqlExecute(channel, query_ch, my_data) This takes way too long (more than 10 hours). Is there a way accomplish this faster? 回答1: TL;DR: LOAD DATA INFILE is one