The default escape character for column names when using translate_sql() is ` I would like for it to be '. I cannot figure out how to accomplish this without casting to a character vector and manually replacing.
Unfortunately not.
I'm trying to implement a filter.myclass that does basic translation for a where clause. It's not a real database back end but rather a list of metadata that will be used to send a query to a rest api.
You were nearly there. You just have to use the con argument of translate_sql(). Either you supply the actual connection to a database or if there is none you can create a dummy connection that inherits from:
a custom class so that you can overwrite sql_escape_ident()
from DBIConnection so that the translation actually works
e.g.
library(dbplyr)
sql_escape_ident.myclass <- function(con, x) sql_quote(x, "'")
dummy_connection <- structure(
list(),
class = c("myclass", "DBIConnection")
)
translate_sql(var > 100, con = dummy_connection)
#> Warning: <myclass> uses an old dbplyr interface
#> ℹ Please install a newer version of the package or contact the maintainer
#> This warning is displayed once every 8 hours.
#> <SQL> 'var' > 100.0