Learn R Programming

snowquery (version 1.2.1)

queryDB: Query a database

Description

Run a SQL query on a Snowflake, Redshift or Postgres database and return the results as a data frame. See the snowquery README for more information on how to pass in your credentials.

Usage

queryDB(
  query,
  conn_name = "default",
  db_type = NULL,
  username = NULL,
  password = NULL,
  host = NULL,
  port = NULL,
  database = NULL,
  warehouse = NULL,
  account = NULL,
  role = NULL,
  sslmode = NULL,
  timeout = 15
)

Value

A data frame containing the results of the query

Arguments

query

A string of the SQL query to execute

conn_name

The name of the connection to use in snowquery_creds.yaml (e.g. "my_snowflake_dwh")

db_type

The type of database to connect to (e.g. "snowflake", "redshift" or "postgres")

username

The username to use for authentication

password

The password to use for authentication

host

The hostname or IP address of the database server

port

The port number to use for the database connection

database

The name of the database to connect to

warehouse

Snowflake The name of the warehouse to use for the Snowflake connection

account

Snowflake The name of the Snowflake account to connect to

role

Snowflake The name of the role to use for the Snowflake connection

sslmode

Whether to use sslmode for the postgres or redshift connection

timeout

The number of seconds to wait for the database to connect successfully

Examples

Run this code
if (FALSE) {
# Query the database and get a dataframe of results
result <- queryDB("SELECT * FROM my_table", conn_name='my_snowflake_dwh')
print(result)
}
if (FALSE) {
# You can also pass in credentials manually
result <- queryDB("SELECT * FROM my_table",
                   db_type='snowflake',
                   username='my_username',
                   password='my_password',
                   account='my_account',
                   database='my_database',
                   warehouse='my_warehouse',
                   role='my_role',
                   timeout=30)
print(result)
}

Run the code above in your browser using DataLab