Learn R Programming

rquery (version 0.5.0)

db_td: Make a table description from a database source.

Description

Build structures (table name, column names, and quoting strategy) needed to represent data from a remote table.

Usage

db_td(db, table_name)

dbi_table(db, table_name)

Arguments

db

database connection

table_name

name of table

Value

a relop representation of the data

Functions

  • dbi_table: old name for db_td

Details

Note: in examples we use rq_copy_to() to create data. This is only for the purpose of having easy portable examples. With big data the data is usually already in the remote database or Spark system. The task is almost always to connect and work with this pre-existing remote data and the method to do this is db_td which builds a reference to a remote table given the table name.

See Also

mk_td, rq_copy_to, materialize, execute, to_sql

Examples

Run this code
# NOT RUN {
if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) {
  my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  rq_copy_to(my_db,
              'd',
              data.frame(AUC = 0.6, R2 = 0.2),
              overwrite = TRUE,
              temporary = TRUE)
  d <- db_td(my_db, 'd')
  print(d)
  sql <- to_sql(d, my_db)
  cat(sql)
  print(DBI::dbGetQuery(my_db, sql))
  cols <- columns_used(d)
  print(cols)

  sql2 <- to_sql(d, my_db, using = "AUC")
  cat(sql2)
  print(DBI::dbGetQuery(my_db, sql2))
  DBI::dbDisconnect(my_db)
}

# }

Run the code above in your browser using DataLab