# Create dummy dataframe
dataframe1 <- rbind("a","b","c")
# Create variable list
variablelist <- unique(dataframe1[,1])
# Loop through adding VARCHAR and commas
sql_var_list <- NULL
for(char in seq_along(variablelist)){
sql_var_list <- paste(sql_var_list,client_variables[char]," VARCHAR,",sep="")
}
# Remove the final comma
sql_var_list <- substr(sql_var_list, 1, nchar(sql_var_list)-1)
# Create structure table SQL string
create_strture_table <- paste("CREATE TABLE (",sql_var_list,")",sep="")
In the above code I'm using the contents from a column in a dataframe in R to create a structure table that will later be created in redshift. The above code is working, but my method seems a bit untidy, as I'm new to R I wonder if someone can suggest a better approach?
paste0("CREATE TABLE (", paste(dataframe1, collapse = " VARCHAR, "), " VARCHAR)")