Execute an SQL query in a database

db_query(
  sql,
  db,
  ...,
  sql_formatter = getOption("dbr.sql_formatter"),
  output_format = getOption("dbr.output_format")
)

Arguments

sql

string

db

database reference by name or object

...

passed to sql_formatter

sql_formatter

function to be applied on sql potentially with ..., eg using glue for string interpolation

output_format

preferred output format that defaults to data.frame, but could be also data.table or tibble as well if the related R package is installed

Value

data.frame with query metadata

See also

Examples

if (FALSE) { options('dbr.db_config_path' = system.file('example_db_config.yaml', package = 'dbr')) db_query('SELECT 42', 'sqlite') db_query('SELECT {40 + 2}', 'sqlite') }