Add to last argument and pass all others through.

to_sql(
  x,
  db,
  ...,
  limit = NULL,
  source_limit = NULL,
  indent_level = 0,
  tnum = mk_tmp_name_source("tsql"),
  append_cr = TRUE,
  using = NULL
)

Arguments

x

rquery operation tree.

db

DBI database handle or rquery_db_info object.

...

generic additional arguments (not used).

limit

numeric if not NULL limit result to this many rows.

source_limit

numeric if not NULL limit sources to this many rows.

indent_level

level to indent.

tnum

temp sub-query name generator.

append_cr

logical if TRUE end with CR.

using

character, if not NULL set of columns used from above.

Value

SQL command

Examples


if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) {
  my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  d1 <- rq_copy_to(my_db, 'd1',
                    data.frame(AUC = 0.6, R2 = 0.2))
  d2 <- rq_copy_to(my_db, 'd2',
                    data.frame(AUC = 0.6, D = 0.3))
  optree <- natural_join(d1, d2, by = "AUC")
  cat(format(optree))
  print(to_sql(optree, my_db))
  DBI::dbDisconnect(my_db)
}
#> mk_td("d1", c(
#>   "AUC",
#>   "R2")) %.>%
#>  natural_join(.,
#>   mk_td("d2", c(
#>     "AUC",
#>     "D")),
#>   jointype = "INNER", by = c('AUC'))
#> [1] "SELECT\n COALESCE(`tsql_35121905591111280462_0000000000`.`AUC`, `tsql_35121905591111280462_0000000001`.`AUC`) AS `AUC`,\n `tsql_35121905591111280462_0000000000`.`R2` AS `R2`,\n `tsql_35121905591111280462_0000000001`.`D` AS `D`\nFROM (\n SELECT\n  `AUC`,\n  `R2`\n FROM\n  `d1`\n) `tsql_35121905591111280462_0000000000`\nINNER JOIN (\n SELECT\n  `AUC`,\n  `D`\n FROM\n  `d2`\n) `tsql_35121905591111280462_0000000001`\nON\n `tsql_35121905591111280462_0000000000`.`AUC` = `tsql_35121905591111280462_0000000001`.`AUC`\n"