run_sql: Execute SQL code on the database

View source: R/run_sql.R

run_sqlR Documentation

Execute SQL code on the database

Description

Execute native SQL code saved in the script on the database. Will execute one statement per script. If the script contains more than one statement, will execute the first statement (e.g. if the script contains ⁠drop table xxx; create table xxx;⁠, only the DROP TABLE statement will be executed). Handles the presence of SQL variable declarations and comments (in ⁠/* */⁠ and ⁠--⁠).

Usage

run_sql(script, conn = con, return_output = F)

Arguments

script

path to the SQL script

conn

connection object created using nhsbsaR::con_nhsbsa()

return_output

set to TRUE if the script is expected to return an output from a SELECT statement.

Examples

## Not run: 
con <- nhsbsaR::con_nhsbsa(database = "DALP")

# E.g. a create table statement
run_sql("INTXXX_BASE_TABLE.sql")

# E.g. a select statement
df <- run_sql("INTXXX_SUMMARY_DATA.sql", return_output = T)

## End(Not run)

nhsbsa-data-analytics/nhsbsaR documentation built on Jan. 25, 2025, 8:54 a.m.