-
-
Save randyzwitch/7566541 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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