why is the .con argument even needed in glue::glue_sql?

Hello there!

That might be a very simple question, but why is the .con argument needed in the glue_sql functions? I mean, say I am just embedding a subquery into another query, what additional information does the connection bring?

Perhaps I am missing something there? I am using Oracle.


I believe that .con argument tells glue_sql what specific sql flavor needs to take to account.

1 Like

The type of quoting needed varies by SQL dialect, so the .con argument is needed to determine what to use.

If you are always using the same type of database / connection you can write a simple wrapper function to avoid needing to pass .con, e.g.

oracle_con <- dbConnect(ROracle::dbDriver("Oracle"), "scott", "tiger")

glue_orc <- function(..., .envir = parent.frame(), .na = DBI::SQL("NULL")) {
  glue::glue_sql(..., .con = oracle_con, .envir = envir, .na = na)

thanks @jimhester and @andresrcs, that is useful!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.