materialize_sql: Materialize a user supplied SQL statement as a table.

View source: R/materialize.R

materialize_sqlR Documentation

Materialize a user supplied SQL statement as a table.

Description

Run the data query with a CREATE TABLE AS .

Usage

materialize_sql(
  db,
  sql,
  table_name = mk_tmp_name_source("rqms")(),
  ...,
  overwrite = TRUE,
  temporary = FALSE,
  qualifiers = NULL
)

Arguments

db

database connecton (rquery_db_info class or DBI connections preferred).

sql

character, user supplied SQL statement.

table_name

character, name of table to create.

...

force later arguments to bind by name.

overwrite

logical if TRUE drop an previous table.

temporary

logical if TRUE try to create a temporary table.

qualifiers

optional named ordered vector of strings carrying additional db hierarchy terms, such as schema.

Value

table description

See Also

db_td, materialize, to_sql, rq_copy_to, mk_td

Examples


if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) {
  my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")

  d <- rq_copy_to(my_db, 'd',
                   data.frame(AUC = 0.6, R2 = 0.2),
                   temporary = TRUE, overwrite = TRUE)
  t <- materialize_sql(my_db, "SELECT AUC, R2, AUC - R2 AS d FROM d")
  print(t)
  print(execute(my_db, t))

  DBI::dbDisconnect(my_db)
}


rquery documentation built on Aug. 20, 2023, 9:06 a.m.