rodbc

rodbc character encoding error with PostgreSQL

空扰寡人 提交于 2019-12-05 05:51:30
I'm getting a new error which I've never gotten before when connecting from R to a GreenPlum PostgreSQL database using RODBC. I've gotten the error using both EMACS/ESS and RStudio, and the RODBC call has worked as is in the past. library(RODBC) gp <- odbcConnect("greenplum", believeNRows = FALSE) data <- sqlQuery(gp, "select * from mytable") > data [1] "22P05 7 ERROR: character 0xc280 of encoding \"UTF8\" has no equivalent in "WIN1252\";\nError while executing the query" [2] "[RODBC] ERROR: Could not SQLExecDirect 'select * from mytable'" EDIT: Just tried querying another table and did get

RODBC not recognizing my odbc settings

空扰寡人 提交于 2019-12-04 16:09:23
问题 I'm running R 2.15.2 on a Red Hat Linux 6 server. My goal is to connect to a MS SQL Server Database on another machine via RODBC. I did my research and downloaded and installed the linux version of the MS SQL ODBC driver from the microsoft support website. I to had build unixODBC version 2.3.0 from source, because it is required by the windows driver and is not in the RHL repos yet (the repo version is 2.2.14). Anyhow, after a bit of work, I finally got the driver installed and configured

How to stop a running query?

南笙酒味 提交于 2019-12-04 15:39:18
问题 I use RODBC to send queries to an SQL-Server. Sometimes they take too much time to run, so I need to cancel them. Clicking the red "stop" button in RStudio yields this error message: R is not responding to your request to interrupt processing so to stop the current operation you may need to terminate R entirely. Terminating R will cause your R session to immediately abort. Active computations will be interrupted and unsaved source file changes and workspace objects will be discarded. Do you

How to upload an image to SQL Server in R

本小妞迷上赌 提交于 2019-12-04 10:55:18
I am creating some graphs which I want to update into a database table. The procedure I am following is: create the graphs as a png/jpeg file. Read that file as a binary vector sqlUpdate My code for steps 2 & 3: pngfile <- file(<filename>, "rb") N <- 1e6 repeat{ pngfilecontents <- readBin(pngfile, what="raw", n=N) if(length(pngfilecontents) == N) N <- 5 * N else break } close(pngfile) There is a table df_DemandPatternMaster in the database with primary key DemandPatternID, with appropriate record in place with NULL value in pngFile field. update.query <- "update df_DemandPatternMaster set "

Efficient way to insert data frame from R to SQL

浪子不回头ぞ 提交于 2019-12-04 10:08:02
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? TL;DR: LOAD DATA INFILE is one order of magnitude faster than multiple INSERT statements, which are themselves one order of magnitude faster

R RODBC putting list of numbers into an IN() statement

ぐ巨炮叔叔 提交于 2019-12-04 08:38:52
I've looked at the ' Pass R variable to RODBC's sqlQuery with multiple entries? ' already but can't seem to get it to work. I'm trying to do an sqlQuery() from R on a SQL Server 2008 R2 db. I'm trying to get a sample from a large db based on row numbers. First I created a list of random numbers: sampRowNum <- sample(seq(1,100000,1), 5000) Then I try to use those numbers in a query using: query1 <- sqlQuery(channel, paste("select * FROM db where row_id in (", sampRowNum,")", sep="")) I get just the results from the db where the row_id is equal to the first number in sampRowNum . Any suggestions

R- create temporary table in sql server from R data frame

主宰稳场 提交于 2019-12-04 06:49:35
I know I can create a temporary table in SQL from R with, for example: require(RODBC) X<- odbcDriverConnect('driver={SQL Server}; server=s001000;database=X1;trusted_connection=true') sqlQuery(X, "create table #temptable (test int)" ) sqlQuery(X, "insert into #temptable(test) values(201508)") doesItWork <- sqlQuery(X, "select * from #temptable") But I would like to create a temporary table in sql server from an R object (I have a table that has the result of previous R calculations and I need to query it against another table in SQL. I don't want to export it as txt and upload it to SQL server.

RODBC query falsely returning zero rows

淺唱寂寞╮ 提交于 2019-12-04 06:46:41
问题 I have come across similar posts, but my issue looks different. I haven't been able to fix the results to these queries with "rows_at_time=1" or "believeNRows = False". I am trying to connect to an Oracle database using RODBC within R. I am able to connect to the database, but I am not retrieving any data, except the column headings. For example I will have zero observations on 18 variables from one table. I do this at work on my PC all the time, but am trying to do this on my macbook pro at

Getting SQL stored procedure results into data.frame format using RODBC

点点圈 提交于 2019-12-04 03:55:41
问题 I am using the RODBC package to query for results in my SQL server. I have a certain stored procedure written that, when executed in my SQL Server Mgmt. studio (for example), returns a table. However, when I run the query through R, it returns character(0) # Execute command... sqlQuery(production,"exec port.tdp_RISK2_ModelRunCompare @ModelRunId1 = 399") Weird thing is... when I do something like... sqlQuery(production,"exec sp_who") I get a table of results... Help? 回答1: I had the same

Problems with RODBC sqlSave

做~自己de王妃 提交于 2019-12-03 13:47:50
I'm having some difficulty inserting a data frame into a mySql database using RODBC. Below is the code I'm using: data <- data.frame(analysedDataID=c(1,2,3), plateWell=c("a","b","c"), screenPlateOrder=c(1,2,3), wellData=c("A","B","C")) con <- odbcConnect(DSN, uid="user_id", pwd="some_password") query <- sqlSave(con, data, tablename = 'wellAnalysedDataTable', rownames=FALSE, append=TRUE) When I try to execute this I get the following error message: Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, : missing columns in 'data' Here is the specific table I'm trying to insert