db_read: Read from a SQL Server database table

View source: R/db_connections.R

db_readR Documentation

Read from a SQL Server database table

Description

Use a database connection to read from an existing SQL Server table with a SQL query.

Usage

db_read(con, query, pull_into_memory = TRUE)

Arguments

con

An odbc database connection. Can be made using build_connection_string. Required.

query

A string, quoted, required. This sql query will be executed against the database you are connected to.

pull_into_memory

Logical, optional, defaults to TRUE. If FALSE, db_read will create a reference to the queried data rather than pulling into memory. Set to FALSE for very large tables.

Details

Use pull_into_memory when working with large tables. Rather than returning the data into memory, this function will return a reference to the specified query. It will be executed only when needed, in a "lazy" style. Or, you can execute using the collect() function.

Value

A tibble of data or reference to the table.

See Also

build_connection_string importFrom dbplyr as.sql

Examples

## Not run: 
my_con <- build_connection_string(server = "HPHI-EDWDEV")
con <- DBI::dbConnect(odbc::odbc(), .connection_string = my_con)
d <- db_read(con,
             "SELECT TOP 10 * FROM [Shared].[Cost].[FacilityAccountCost]")

# Get a reference and collect later
ref <- db_read(con,
               "SELECT TOP 10 * FROM [Shared].[Cost].[FacilityAccountCost]",
               pull_into_memory = FALSE)
d <- collect(ref)

## End(Not run)


healthcareai documentation built on Sept. 5, 2022, 5:12 p.m.