db_read: Read from a SQL Server database table

Description Usage Arguments Details Value See Also Examples

View source: R/db_connections.R

Description

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

Usage

1
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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## 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. 2, 2018, 1:03 a.m.