Skip to content

Instantly share code, notes, and snippets.

@sharlagelfand
Created February 16, 2018 18:54
Show Gist options
  • Save sharlagelfand/acd31a1f3e28eb1a1bbbdb841d79cd26 to your computer and use it in GitHub Desktop.
Save sharlagelfand/acd31a1f3e28eb1a1bbbdb841d79cd26 to your computer and use it in GitHub Desktop.
Inserting data into redshift from R
library(glue)
library(RPostgreSQL)
library(DBI)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,
host=Sys.getenv("JDBCURL"),
port = Sys.getenv("PORT"),
dbname = Sys.getenv("DBNAME"),
user = Sys.getenv("USER"),
password = Sys.getenv("PW"))
users_syntax <- "123, 1234, 12345"
query <- glue("
INSERT INTO table_name (user_id)
VALUES ({users})",
users = users_syntax)
%>% as.character
dbSendQuery(con, query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment