sql-statements: Run parametric SQL statements and queries

query_sqlR Documentation

Run parametric SQL statements and queries

Description

Run parametric SQL statements and queries

Usage

query_sql(.sql, ..., .envir = parent.frame(), .verbose = FALSE)

execute_sql(.sql, ..., .envir = parent.frame(), .verbose = FALSE)

Arguments

.sql

string containing the parametric SQL expression.

...

Arguments passed on to write_sql

.envir

environment in which to lookup parametric values not found in .... By default, looks at the current calling environment.

.verbose

Whether to display the resulting SQL call, useful during development.

Details

See write_sql() to see how ... parameters must be defined.

These functions are basically simple wrappers around DBI::dbExecute() and DBI::dbGetQuery() and as such serve equivalent purposes:

  • execute_sql() is meant for statements which modify the database (UPDATE, DELETE, ⁠DROP TABLE⁠, etc)

  • query_sql() is meant for SELECT queries.

Value

For query_sql, the output of the SQL query as a data.frame.

For execute_sql, the number of rows modified by the statement.

Examples

## Not run: 
bar <- 1
get_query("
  SELECT *
  From Foo
  WHERE a = {bar}")
# output of "SELECT * From Foo WHERE a = 1"

## End(Not run)


pnacht/simplysql documentation built on Sept. 5, 2024, 8:46 p.m.