Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass vars to tbl(con, sql) #530

Closed
okhoma opened this issue Nov 4, 2020 · 0 comments
Closed

Unable to pass vars to tbl(con, sql) #530

okhoma opened this issue Nov 4, 2020 · 0 comments

Comments

@okhoma
Copy link
Contributor

okhoma commented Nov 4, 2020

Function dbplyr::tbl_sql() has parameter vars, but I am unable to pass it from dplyr::tbl.DBIConnection(), because ... are ignored in dbplyr::tbl.src_dbi().

Here is a simple test:

> trace(dbplyr:::db_query_fields.DBIConnection)
> class(con)
[1] "Microsoft SQL Server"
attr(,"package")
[1] ".GlobalEnv"
> tbl(con, sql("select id, name from test"))
trace: db_query_fields.DBIConnection(con, ...)
# Source:   SQL [?? x 2]
# Database: Microsoft SQL Server 12.00.2000[xxxx]
     id name 
  <int> <chr>
1     1 test1
2     2 test2
> tbl(con, sql("select id, name from test"), vars = c("id", "name"))
trace: db_query_fields.DBIConnection(con, ...)
# Source:   SQL [?? x 2]
# Database: Microsoft SQL Server 12.00.2000[xxxx]
     id name 
  <int> <chr>
1     1 test1
2     2 test2

Note, that db_query_fields() is called in both cases.

Parameter vars can be helpful not just to save one request to database, but also to be able to fetch hidden SQL Server temporal tables' period columns, which are not returned by db_query_fields(). For now, my workaround is to use dbplyr::tbl_sql() directly.

I propose to modify tbl.dbi_src() to pass the dots down to tbl_sql:

tbl.src_dbi <- function(src, from, ...) {
  subclass <- class(src$con)[[1]] # prefix added by dplyr::make_tbl
  tbl_sql(c(subclass, "dbi"), src = src, from = from, ...)
}
@hadley hadley closed this as completed in 76caef4 Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant