Skip to content

Instantly share code, notes, and snippets.

@fredbenenson
Last active December 28, 2015 21:39
Show Gist options
  • Save fredbenenson/7566412 to your computer and use it in GitHub Desktop.
Save fredbenenson/7566412 to your computer and use it in GitHub Desktop.
Redshift Wrapper & Credentials
# Install the Redshift R library:
# https://github.com/pingles/redshift-r
# install.packages("~/Downloads/redshift-r-master", dependencies = T, repos = NULL, type = "source")
library(redshift)
redshift <- redshift.connect("jdbc:postgresql://REDSHIFT_DB:5439/DB_NAME", "LOGIN", "PASSWORD")
# Example Query:
data <- dbGetQuery(redshift, "SELECT COUNT(*) FROM table")
# Function to use a .sql file directly, handy if you're using version control for queries:
redshift_query_from_sql <- function (query_file) {
dbGetQuery(redshift,
paste(
scan(query_file,
what = "character",
sep = '\n'
),
collapse = '\n')
)
}
# Example:
# data <- redshift_query_from_sql("file_with_sql.sql")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment