1

I'm writing a query using RPostgreSQL meant to fill a table one time. I really have no intention to do anything else with the data within R. I just need it for is to run the function to fill that table.

library(data.table)
library (RPostgreSQL)


    MakeAndGetQuery <- function(id) {
      q <- paste0("INSERT INTO table_a SELECT * FROM table_c WHERE  client_id = ",
                   id, 
                   " AND event_date = CURRENT_DATE - 1")
      as.data.table(dbGetQuery(conn2, q))
    }


all_yer_data <- rbindlist(lapply(generate_id$client_id, MakeAndGetQuery))
        setkey(all_yer_data, id, ...)

So my question is, will not doing anything with the dataframe within R impact if it runs successfully? In theory, that SQL statement shouldn't even produce any results within R. It's using INSERT INTO from Redshift, so if I ran that in Redshift, it wouldn't return any results, just a message saying it was successfull and "5 Rows affected"

  • I'm assuming that `table_c` is the data frame to which you are referring. No, I would not expect R to mutate that data frame from doing an insert into Postgres. – Tim Biegeleisen Nov 02 '18 at 01:19
  • @TimBiegeleisen My apologies. I left out a part on the original function. `table_c` is part of the hypothetical query I would be inserting into the table (which I've now edited as `table_b` –  Nov 02 '18 at 01:24
  • So you don't want to return any results within R? Replace `dbGetQuery` with `dbSendQuery`? – MKa Nov 02 '18 at 01:36

0 Answers0