Description
dbplyr
tries to create a subset of the tidyverse that will work on both database backends, and in-memory tibble backends. Unfortunately there are currently no string-matching functions in that subset, because certain backends (e.g. SQLite) don't support regex by default.
My proposal is therefore to support the "fixed strings" versions of common string matching functions, because (to my knowledge), all SQL backends support the LIKE
operation.
The way I would envisage this working is:
DBI::dbConnect(RSQLite::SQLite(), ":memory:") |>
dplyr::tbl("table_name") |>
dplyr::filter(stringr::str_detect(some_column, fixed("foo")))
This would translate to something like SELECT * FROM table_name WHERE some_column LIKE %foo%
.
However, this would fail, because it requires full regex support:
DBI::dbConnect(RSQLite::SQLite(), ":memory:") |>
dplyr::tbl("table_name") |>
dplyr::filter(stringr::str_detect(some_column, "foo"))
I imagine this could be implemented using an sql_translator
input that provides an str_detect
implementation that fails when the input pattern is anything other than fixed
. In theory this could be extended to support base::grep(fixed=TRUE)
and other similar functions.