rodbc

RODBC string getting truncated

点点圈 提交于 2019-12-19 17:56:53
问题 I am fetching data from MySql Server into R using RODBC. So in one column of the database is a character vector SELECT MAX(CHAR_LENGTH(column)) FROM reqtable; RETURNS 26566 Now I will show you an example how I am running into the problem `library(RODBC) con <- odbcConnect("mysqlcon") rslts <- as.numeric(sqlQuery(con, "SELECT CHAR_LENGTH(column) FROM reqtable LIMIT 10", as.is=TRUE)[,1]) ` returns > rslts [1] 62 31 17 103 30 741 28 73 25 357 where as rslts <- nchar(as.character(sqlQuery(con,

RODBC command 'sqlQuery' has problems with table variables in t-SQL

杀马特。学长 韩版系。学妹 提交于 2019-12-19 09:19:34
问题 I am using the RODBC package which I am applying on a Microsoft SQL Server 2012. Now I have discovered a phenomenon that puzzles me. If I run the following query with the RODBC command sqlQuery, then, in R, I will get back an empty data frame with the columns Country, CID, PriceID and WindID. DECLARE @tbl_IDs TABLE ( Country nvarchar(30), CID nvarchar(5), PriceID int, WindID int ) SELECT * FROM @tbl_Ids So far, everything is fine. However, if I try to write a record to the table variable and

Show all open RODBC connections

谁都会走 提交于 2019-12-19 04:18:22
问题 Does anyone know how to do this? showConnections won't list any open connections from odbcConnect. 回答1: You can narrow down your search in the following way, which will return all variables of your environment currently of the class RODBC. envVariables<-ls() bools<-sapply(envVariables, function(string){ class(get(string))=="RODBC" }) rodbcObj<-envVariables[bools] Closed connections are still of the class RODBC though, so there is still a little work to be done here. We can define a function,

MS-SQL Bulk Insert with RODBC

南笙酒味 提交于 2019-12-18 04:52:06
问题 Is it possible to perform a bulk insert into an MS-SQL Server (2000, 2005, 2008) using the RODBC package? I know that I can do this using freebcp, but I'm curious if the RODBC package implements this portion of the Microsoft SQL API and if not, how difficult it would be to implement it. 回答1: check out the new odbc and DBI packages. DBI::dbWriteTable writes around 20,000 records per second... Much much faster than the Row Inserts from RODBC::sqlSave() 回答2: You're probably looking for ?sqlSave

How to insert a dataframe into a SQL Server table?

浪尽此生 提交于 2019-12-17 15:44:18
问题 I'm trying to upload a dataframe to a SQL Server table, I tried breaking it down to a simple SQL query string.. library(RODBC) con <- odbcDriverConnect("driver=SQL Server; server=database") df <- data.frame(a=1:10, b=10:1, c=11:20) values <- paste("(",df$a,",", df$b,",",df$c,")", sep="", collapse=",") cmd <- paste("insert into MyTable values ", values) result <- sqlQuery(con, cmd, as.is=TRUE) ..which seems to work but does not scale very well. Is there an easier way? 回答1: [edited] Perhaps

SQL Server RODBC Connection

淺唱寂寞╮ 提交于 2019-12-17 06:24:13
问题 Does anyone have a connection string example for using RODBC and connecting to MS SQL Server 2005 or 2008. Thank you. 回答1: library(RODBC) dbhandle <- odbcDriverConnect('driver={SQL Server};server=mysqlhost;database=mydbname;trusted_connection=true') res <- sqlQuery(dbhandle, 'select * from information_schema.tables') 回答2: Taken from a posting to r-help: library(RODBC) channel <- odbcDriverConnect("driver=SQL Server;server=01wh155073") initdata<- sqlQuery(channel,paste("select * from test_DB .

R: loss of precision when POSIXct binding with datetime (sql server) [duplicate]

对着背影说爱祢 提交于 2019-12-13 20:25:01
问题 This question already has answers here : Odd behavor with POSIXct/POSIXlt and subsecond accuracy (1 answer) R xts: .001 millisecond in index (2 answers) Closed 6 years ago . When working to update a sql server table with a datetime field, I had the following observations: > options(digits.secs = 3) > z <- strptime("20/2/06 11:16:16.68", "%d/%m/%y %H:%M:%OS") > z [1] "2006-02-20 11:16:16.67" > z <- strptime("20/2/06 11:16:16.683", "%d/%m/%y %H:%M:%OS") > z [1] "2006-02-20 11:16:16.682" We can

RODBC::sqlSave - problems creating/appending to a table

橙三吉。 提交于 2019-12-13 19:16:10
问题 Related to several other questions on the RODBC package, I'm having problems using RODBC::sqlSave to write to a table on a SQL Server database. I'm using MS SQL Server 2008 and 64-bit R on a Windows RDP. The solution in the 3rd link (questions) does work [ sqlSave(ch, df) ]. But in this case, it writes to the wrong data base. That is, my default DB is "C2G" but I want to write to "BI_Sandbox". And it doesn't allow for options such as rownames, etc. So there still seems to be a problem in the

Impossibility of loading a “Excel 5.0/7.0 (BIFF5) format” file in R

荒凉一梦 提交于 2019-12-13 15:08:03
问题 There's a multitude of ways to load Excel files in R, as reported here: http://www.milanor.net/blog/?p=779 However, I've tried most of the options out there (RODBC, xlsx, gdata, XLConnect) and just cannot make R load this particular file, published by the British government in 2013: http://www.ons.gov.uk/ons/rel/npp/national-population-projections/2012-based-projections/rft-table-a3-4-principal-projection---england-population-single-year-of-age.xls Here's an example of my failed attempts: #

RPostgreSQL - R Connection to Amazon Redshift - How to WRITE/Post Bigger Data Sets

你离开我真会死。 提交于 2019-12-13 13:20:45
问题 I'm experimenting with how to connect R with Amazon's Redshift - and publishing a short blog for other newbies. Some good progress - I'm able to do most things (create tables, select data, and even sqlSave or dbSendQuery 'line by line' HOWEVER, I have not found a way to do a BULK UPLOAD of a table in one shot (e.g. copy the whole 5X150 IRIS table/data frame to Redshift) - that doesnt take more than a minute. Question: Any advice for a newish person to RPostgreSQL on how to write/upload a