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

Support cur_column() #951

Closed
mgirlich opened this issue Jul 29, 2022 · 0 comments · Fixed by #957
Closed

Support cur_column() #951

mgirlich opened this issue Jul 29, 2022 · 0 comments · Fixed by #957
Milestone

Comments

@mgirlich
Copy link
Collaborator

I tried to use across() to apply some custom sql to multiple columns. But I had no luck with it.

library(dbplyr)
library(dplyr, warn.conflicts = FALSE)

iris %>% 
  slice(1:2) %>% 
  transmute(across(1:2, ~ sql(paste0(cur_column(), "::jsonb"))))
#>                Sepal.Length              Sepal.Width
#> 1 <SQL> Sepal.Length::jsonb <SQL> Sepal.Width::jsonb
#> 2 <SQL> Sepal.Length::jsonb <SQL> Sepal.Width::jsonb

iris_db <- tbl_memdb(iris)
iris_db %>% 
  transmute(across(1:2, ~ sql(paste0(cur_column(), "::jsonb")))) %>% 
  show_query()
#> <SQL>
#> SELECT
#>   cur_column() || '::jsonb' AS `Sepal.Length`,
#>   cur_column() || '::jsonb' AS `Sepal.Width`
#> FROM `iris`

iris_db %>% 
  transmute(across(1:2, ~ sql(!!paste0(cur_column(), "::jsonb")))) %>% 
  show_query()
#> Error in `cur_column()`:
#> ! Must be used inside `across()`.

Created on 2022-07-29 by the reprex package (v2.0.1)

@mgirlich mgirlich added this to the 2.3.0 milestone Jul 29, 2022
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