r-dbi

In R connected to a database through ODBC, how do I disconnect after running one query to send another query without cancelling the previous?

若如初见. 提交于 2021-01-28 07:11:22
问题 I am new to R and new to Stack Overflow, so apologies if I don't post this correctly! I have R linked to an Access database using the ODBC and DBI packages. I scoured the internet and couldn't find a way to write an update query, so I've created a loop that manually pretty much does the same thing. The problem is that to do this, I am using the dbSendStatement function. It seems that when you use that function you need a way to then end it before moving onto another query, or else you get

In R connected to an Access Database through ODBC, how can I update a text field?

左心房为你撑大大i 提交于 2021-01-05 07:22:05
问题 I have R linked to an Access database using the ODBC and DBI packages. I scoured the internet and couldn't find a way to write an update query, so I'm using the dbSendStatement function to update entries individually. Combined with a for loop, this effectively works like an update query with one snag - when I try to update any field in the database that is text I get an error that says "[Microsoft][ODBC Microsoft Access Driver] One of your parameters is invalid." DBI::dbSendStatement(conn =

In R connected to an Access Database through ODBC, how can I update a text field?

时光毁灭记忆、已成空白 提交于 2021-01-05 07:18:44
问题 I have R linked to an Access database using the ODBC and DBI packages. I scoured the internet and couldn't find a way to write an update query, so I'm using the dbSendStatement function to update entries individually. Combined with a for loop, this effectively works like an update query with one snag - when I try to update any field in the database that is text I get an error that says "[Microsoft][ODBC Microsoft Access Driver] One of your parameters is invalid." DBI::dbSendStatement(conn =

How to pipe SQL into R's dplyr?

*爱你&永不变心* 提交于 2020-08-07 05:28:24
问题 I can use the following code in R to select distinct rows in any generic SQL database. I'd use dplyr::distinct() but it's not supported in SQL syntax. Anyways, this does indeed work: dbGetQuery(database_name, "SELECT t.* FROM (SELECT t.*, ROW_NUMBER() OVER (PARTITION BY column_name ORDER BY column_name) AS SEQNUM FROM table_name t ) t WHERE SEQNUM = 1;") I've been using it with success, but wonder how I can pipe that same SQL query after other dplyr steps, as opposed to just using it as a

How to pipe SQL into R's dplyr?

北城余情 提交于 2020-08-07 05:28:02
问题 I can use the following code in R to select distinct rows in any generic SQL database. I'd use dplyr::distinct() but it's not supported in SQL syntax. Anyways, this does indeed work: dbGetQuery(database_name, "SELECT t.* FROM (SELECT t.*, ROW_NUMBER() OVER (PARTITION BY column_name ORDER BY column_name) AS SEQNUM FROM table_name t ) t WHERE SEQNUM = 1;") I've been using it with success, but wonder how I can pipe that same SQL query after other dplyr steps, as opposed to just using it as a

Mutate variables in database tables directly using dplyr

谁说我不能喝 提交于 2020-01-10 10:47:25
问题 Here is mtcars data in the MonetDBLite database file. library(MonetDBLite) library(tidyverse) library(DBI) dbdir <- getwd() con <- dbConnect(MonetDBLite::MonetDBLite(), dbdir) dbWriteTable(conn = con, name = "mtcars_1", value = mtcars) data_mt <- con %>% tbl("mtcars_1") I want to use dplyr mutate to create new variables and add (commit!) that to the database table? Something like data_mt %>% select(mpg, cyl) %>% mutate(var = mpg/cyl) %>% dbCommit(con) The desired output should be same when we

Can I run an SQL update statement using only dplyr syntax in R

廉价感情. 提交于 2020-01-01 08:56:06
问题 I need to update column values conditionnaly on other columns in some PostgreSQL database table. I managed to do it writing an SQL statement in R and executing it with dbExecute from DBI package. library(dplyr) library(DBI) # Establish connection with database con <- dbConnect(RPostgreSQL::PostgreSQL(), dbname = "myDb", host="localhost", port= 5432, user="me",password = myPwd) # Write SQL update statement request <- paste("UPDATE table_to_update", "SET var_to_change = 'new value' ", "WHERE

dbGetQuery returns date that differs by an hour

假装没事ソ 提交于 2019-12-25 13:38:10
问题 In R I am running the following query to retrieve data: test <- dbGetQuery(conn = GetConnection("default"), statement = "SELECT PK_FK_RW_BOND_HOLDING_VAL_BOND, PK_CASHFLOW_DAT FROM RW_CASH_FLOWS_ON_BONDS WHERE PK_FK_RW_BOND_HOLDING_VAL_BOND = 'AT0000385745' OR PK_FK_RW_BOND_HOLDING_VAL_BOND = 'RU000A0JV7J9'") This returns PK_FK_RW_BOND_HOLDING_VAL_BOND PK_CASHFLOW_DAT RU000A0JV7J9 2018-01-14 23:00:00 RU000A0JV7J9 2017-01-14 23:00:00 RU000A0JV7J9 2019-08-01 00:00:00 RU000A0JV7J9 2019-01-31 23

How do I access nested SQL tables in R?

戏子无情 提交于 2019-12-25 01:49:18
问题 From R Studio's ODBC database documentation I can see a simple example of how to read a SQL table into an R data frame: data <- dbReadTable(con, "flights") Let me paste a graphic of the BGBUref table(?) I'm trying to read to an R data frame. This is from my connection pane in R studio. If I use the same syntax as above, where con is the output of my dbConnect(...) I get the following: df <- dbReadTable(con, "BGBURef") #> Error: <SQL> 'SELECT * FROM "BGBURef"' nanodbc/nanodbc.cpp:1587: 42S02:

dbReadTable error in R: invalid object name

断了今生、忘了曾经 提交于 2019-12-23 03:31:23
问题 I've been scouring stackoverflow and google for an hour trying to figure out why my table won't show up. So far solutions that have worked for others, don't work for me. I'm connecting to a database like this: library(DBI) library(dplyr) con <- dbConnect(odbc::odbc(), .connection_string = "Driver={SQL Server};", user = rstudioapi::askForPassword("Your computer usename e.g. SmithJo"), password = rstudioapi::askForPassword("Your computer password (e.g. to login to Windows)"), port = 1433,