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

dbplyr::sql_render generates error when using CTEs and dplyr::union #1557

Open
aguynamedryan opened this issue Nov 20, 2024 · 1 comment · May be fixed by #1558
Open

dbplyr::sql_render generates error when using CTEs and dplyr::union #1557

aguynamedryan opened this issue Nov 20, 2024 · 1 comment · May be fixed by #1558

Comments

@aguynamedryan
Copy link

I ran into an error when attempting union some tables with the CTE option turned on.

tib <- tibble::tibble(a = c(1))
con <- dbplyr::simulate_dbi()
t <- dbplyr::tbl_lazy(tib, con = con)
tu <- dplyr::union(t, t)
dbplyr::sql_render(tu, sql_options = dbplyr::sql_options(cte = TRUE))
#> Error in qry$unions$table[[i]]: subscript out of bounds

Created on 2024-11-19 with reprex v2.1.1

I doubt it is relevant to the issue, but I'm using a combination of simulated DBI backends and lazy tables run through dplyr verbs to build up SQL queries. I then use dbplyr::sql_render to produce SQL statements. I was experimenting with using CTEs and when I set cte = TRUE, I got this error.

@aguynamedryan
Copy link
Author

The error seems to come from this line

Interestingly, this test passes, but a more simple variation of the same test does not:

lf1 %>%
  union_all(lf2) %>%
  show_query(sql_options = sql_options(cte = TRUE))
#> Error in qry$unions$table[[i]]: subscript out of bounds

aguynamedryan added a commit to aguynamedryan/dbplyr that referenced this issue Nov 21, 2024
@aguynamedryan aguynamedryan linked a pull request Nov 21, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant