rodbc

Pass R Vector to Sql query

不羁的心 提交于 2019-11-29 17:50:54
I'm using RODBC package to access my sql database in R. I haven't been able to find any useful information on how to pass a vector from R to sql as a vector. id <- ('00003', '00100') query <- sqlQuery(channel = channel, query = "select * from prod_cust_vw.store_dim where store_num in id") I would like to pass the id vector to sql rather than hard coding it. 1) sprintf Convert id into a string suitable for inclusion in the SQL statement and then insert it into the sql string using sprintf See ?sprintf . id <- c('00003', '00100') idString <- toString(sprintf("'%s'", id)) # "'00003', '00100'" sql

Reconstitute PNG file stored as RAW in SQL Database

我的未来我决定 提交于 2019-11-29 14:52:04
I am working toward writing a report from a SQL database (Windows SQL Server) that will require certain people to sign the report before submitting it to the client. We are hoping to have a system where these people can authorize their signature in the database, and then we can use an image of their signature stored in the database and place it on the report generated by LaTeX. The signature images are created as PNGs, then stored in the database in a field with type varbinary . In order to use the signature in the report, I need to reconstitute the PNG to a file that I can with

How to pass data.frame for UPDATE with R DBI

有些话、适合烂在心里 提交于 2019-11-29 09:44:10
问题 With RODBC, there were functions like sqlUpdate(channel, dat, ...) that allowed you pass dat = data.frame(...) instead of having to construct your own SQL string. However, with R's DBI, all I see are functions like dbSendQuery(conn, statement, ...) which only take a string statement and gives no opportunity to specify a data.frame directly. So how to UPDATE using a data.frame with DBI? 回答1: Really late, my answer, but maybe still helpful... There is no single function (I know) in the DBI/odbc

RODBC sqlSave table creation problems

倾然丶 夕夏残阳落幕 提交于 2019-11-29 02:16:55
I'm having trouble creating a table using RODBC's sqlSave (or, more accurately, writing data to the created table). This is different than the existing sqlSave question/answers, as the problems they were experiencing were different, I can create tables whereas they could not and I've already unsuccesfully incorporated their solutions, such as closing and reopening the connection before running sqlSave, also The error message is different, with the only exception being a post that was different in the above 2 ways I'm using MS SQL Server 2008 and 64-bit R on a Windows RDP. I have a simple data

How to convert searchTwitter results (from library(twitteR)) into a data.frame?

妖精的绣舞 提交于 2019-11-29 00:53:20
问题 I am working on saving twitter search results into a database (SQL Server) and am getting an error when I pull the search results from twitteR. If I execute: library(twitteR) puppy <- as.data.frame(searchTwitter("puppy", session=getCurlHandle(),num=100)) I get an error of: Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class structure("status", package = "twitteR") into a data.frame This is important because in order to use RODBC to add this to a table using sqlSave

RODBC loses time values of datetime when result set is large

落爺英雄遲暮 提交于 2019-11-28 21:32:06
So this is VERY strange. RODBC seems to drop the time portion of DateTime SQL columns if the result set is large enough. (The queries are running against an SQL Server 2012 machine, and, yes, when I run them on the SQL Server side they produce identical and proper results, regardless of how many rows are returned.) For example, the following works perfectly: myconn <- odbcConnect(dsnName, uid, pwd) results <- sqlQuery(myconn, "SELECT TOP 100 MyID, MyDateTimeColumn from MyTable ORDER BY MyDateTimeColumn DESC") close(myconn) In R, the following works as expected: > results$MyDateTimeColumn[3] [1

Can I gracefully include formatted SQL strings in an R script?

可紊 提交于 2019-11-28 19:53:56
I'm working in an R script that uses a long SQL string, and I would like to keep the query relatively free of other markup so as to allow copying and pasting between editors and applications. I'd also like the ability to split the query across lines for better readability. In the RODBC documentation, the paste function is used to build the query out of separate chunks, but I'd prefer something less kludgy and with fewer quotes and commas. Thanks for your help. you can override the %+% operator to have better string concatination syntax: '%+%' <- function(x,y) paste(x,y,sep="") y<-"y1" x<-

Connect R and Vertica using RODBC

痴心易碎 提交于 2019-11-28 11:24:30
This is my first time connecting to Vertica. I have already connected to a MySQL database sucessfully by using RODBC library. I have the database setup in vertica and I installed the windows 64-bit ODBC driver from https://my.vertica.com/download-community-edition/ When I tried to connect to vertica using R, I get the below error: channel = odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") Warning messages: 1: In odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") : [RODBC] ERROR: state IM002, code 0,

Pass R Vector to Sql query

自闭症网瘾萝莉.ら 提交于 2019-11-28 10:26:36
问题 I'm using RODBC package to access my sql database in R. I haven't been able to find any useful information on how to pass a vector from R to sql as a vector. id <- ('00003', '00100') query <- sqlQuery(channel = channel, query = "select * from prod_cust_vw.store_dim where store_num in id") I would like to pass the id vector to sql rather than hard coding it. 回答1: 1) sprintf Convert id into a string suitable for inclusion in the SQL statement and then insert it into the sql string using sprintf

Reconstitute PNG file stored as RAW in SQL Database

南笙酒味 提交于 2019-11-28 08:48:25
问题 I am working toward writing a report from a SQL database (Windows SQL Server) that will require certain people to sign the report before submitting it to the client. We are hoping to have a system where these people can authorize their signature in the database, and then we can use an image of their signature stored in the database and place it on the report generated by LaTeX. The signature images are created as PNGs, then stored in the database in a field with type varbinary . In order to