dbplyr

R: Best Practices - dplyr and odbc multi table actions (retrieved from SQL)

风格不统一 提交于 2020-05-13 06:57:26
问题 Say you have your tables stores in an SQL server DB, and you want to perform multi table actions, i.e. join several tables from that same database. Following code can interact and receive data from SQL server: library(dplyr) library(odbc) con <- dbConnect(odbc::odbc(), .connection_string = "Driver={SQL Server};Server=.;Database=My_DB;") Table1 <- tbl(con, "Table1") Table1 # View glimpse of Table1 Table2 <- tbl(con, "Table2") Table2 # View glimpse of Table2 Table3 <- tbl(con, "Table3") However

how to generate SQL from dbplyr without a database connection?

限于喜欢 提交于 2020-02-22 04:12:30
问题 I currently have access to an Apache Hive database via the beeline CLI. We are still negotiating with IT to get R on the server. Until that time, I would like to (ab)use the R dbplyr package to generate SQL queries on another machine, copy them over, and run them as raw SQL. I have used sql_render in dbplyr in the past in instances where I had a valid database connection, but I do not know how to do this without a valid database connection. The ideal case, for me would be something like: con

how to generate SQL from dbplyr without a database connection?

安稳与你 提交于 2020-02-22 04:12:00
问题 I currently have access to an Apache Hive database via the beeline CLI. We are still negotiating with IT to get R on the server. Until that time, I would like to (ab)use the R dbplyr package to generate SQL queries on another machine, copy them over, and run them as raw SQL. I have used sql_render in dbplyr in the past in instances where I had a valid database connection, but I do not know how to do this without a valid database connection. The ideal case, for me would be something like: con

how to generate SQL from dbplyr without a database connection?

别说谁变了你拦得住时间么 提交于 2020-02-22 04:10:28
问题 I currently have access to an Apache Hive database via the beeline CLI. We are still negotiating with IT to get R on the server. Until that time, I would like to (ab)use the R dbplyr package to generate SQL queries on another machine, copy them over, and run them as raw SQL. I have used sql_render in dbplyr in the past in instances where I had a valid database connection, but I do not know how to do this without a valid database connection. The ideal case, for me would be something like: con

how to generate SQL from dbplyr without a database connection?

和自甴很熟 提交于 2020-02-22 04:10:10
问题 I currently have access to an Apache Hive database via the beeline CLI. We are still negotiating with IT to get R on the server. Until that time, I would like to (ab)use the R dbplyr package to generate SQL queries on another machine, copy them over, and run them as raw SQL. I have used sql_render in dbplyr in the past in instances where I had a valid database connection, but I do not know how to do this without a valid database connection. The ideal case, for me would be something like: con

dbplyr copy_to not saving table to database

你。 提交于 2020-02-02 15:05:40
问题 I am trying to copy a local dataframe from R to my db2 database. I have permissions to write to the table and I have verified the connection is working. I am using: copy_to(connection, data.frame, name = my_table_name) I am getting the following error and it doesnt make sense to me. The object it says does not exist is the very object I am trying to create. What am I doing wrong? Error in typeof(x) : object 'my_table_name' not found 回答1: by default, copy_to() tries to create a temporary table

How to give dplyr a SQL query and have it return a remote tbl object?

爷,独闯天下 提交于 2020-01-15 06:50:09
问题 Say I have a remote tbl open using dbplyr, and I want to use a SQL query on it (maybe because there's not dbplyr translation for what I want to do), how do I give it such that it returns a remote tbl object? The DBI::dbGetQuery() function allows you to give a query to db, but it returns a data frame on memory, and not an remote tbl object. For example, say you already have a connection con open to a db, you can create a table like this: library(tidyverse) x_df <- expand.grid(A = c('a','b','c'

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

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:

Can dplyr for SQL translate == NA to IS NULL in filters?

大憨熊 提交于 2019-12-24 16:04:05
问题 I'm trying to use dplyr to query a SQL database, matching on provided arguments. id <- tbl(conn, "My_Table") %>% filter(Elem1 == elem1 & Elem2 == elem2 & Elem3 == elem3) %>% select(Id) %>% collect() However, it's possible that any of elem1 , elem2 , or elem3 might be NA. Ideally, I'd like the query to translate them to the SQL IS NULL statement. For example, if elem1 is 1, elem2 is NA, and elem3 is 3, I'd like the translated query to be: SELECT Id FROM My_Table WHERE Elem1 == 1 AND Elem2 IS