Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions R/redshift.r
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ redshift.unload <- function(conn, query, filename, aws.accesskey, aws.secretkey,
print(unload.query)
dbSendUpdate(conn,unload.query)
}

redshift.insertTable = function(conn, dataframe, rs.tablename){
insertValuesString = paste(apply(dataframe,1,function(x){
paste0("(",paste(sapply(x,function(val){
paste0("'",gsub("'","''",val),"'")
}),collapse = ","),")")
}),collapse = ',')

insertQuery = paste0("Insert into ",rs.tablename," values ",insertValuesString)
dbSendUpdate(conn,insertQuery)
}
27 changes: 27 additions & 0 deletions man/redshift.insertTable.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
\name{redshift.insertTable}
\alias{redshift.insertTable}
\title{Insert a data.frame into a redshift table}
\description{
Insert a data.frame into a redshift table. Encoding must be utf-8. Use iconv() to enforce so.
}
\usage{
redshift.insertTable(conn, dataframe, rs.tablename)
}
\arguments{
\item{conn}{The database connection}
\item{dataframe}{The R dataframe to be inserted}
\item{rs.tablename}{The destination Redshift table}
}
\value{
NA
}
\author{
Eeshan Chatterjee
}
\examples{
require(redshift)
# conn <- redshift.connect("jdbc:postgresql://blah.blah.eu-west-1.redshift.amazonaws.com:5439/data", "username", "password")
#redshift.insertTable(conn,dataframe = myDF, rs.tablename = "myRSTable")
}
\keyword{ insert table }