db_td: Construct a table description from a database source.

View source: R/table_source.R

db_tdR Documentation

Construct 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, ..., qualifiers = NULL, limit_was = 6L)

dbi_table(db, table_name, ..., qualifiers = NULL, limit_was = 6L)

Arguments

db

database connection

table_name

name of table

...

not used, force later argument to bind by name

qualifiers

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

limit_was

optional, row limit used to produce head_sample. If NULL no head_sample is produced and rq_colnames is used to get column names.

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.

Value

a relop representation of the data

Functions

  • dbi_table(): old name for db_td

See Also

mk_td, local_td, rq_copy_to, materialize, execute, to_sql

Examples


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)
}


WinVector/rquery documentation built on Aug. 24, 2023, 11:12 a.m.