Un "dplyr
-seulement" la solution serait celle-ci
tbl(my_con, "my_table") %>%
filter(batch_name %like% "batch_A_%") %>%
collect()
reprex complet :
suppressPackageStartupMessages({
library(dplyr)
library(dbplyr)
library(RPostgreSQL)
})
my_con <-
dbConnect(
PostgreSQL(),
user = "my_user",
password = "my_password",
host = "my_host",
dbname = "my_db"
)
my_table <- tribble(
~batch_name, ~value,
"batch_A_1", 1,
"batch_A_2", 2,
"batch_A_2", 3,
"batch_B_1", 8,
"batch_B_2", 9
)
copy_to(my_con, my_table)
tbl(my_con, "my_table") %>%
filter(batch_name %like% "batch_A_%") %>%
collect()
#> # A tibble: 3 x 2
#> batch_name value
#> * <chr> <dbl>
#> 1 batch_A_1 1
#> 2 batch_A_2 2
#> 3 batch_A_2 3
dbDisconnect(my_con)
#> [1] TRUE
Cela fonctionne car toutes les fonctions que dplyr ne sait pas comment traduire seront transmises telles quelles, voir ?dbplyr::translate\_sql
.
Coup de chapeau à @PaulRougieux pour son récent commentaireici