I am trying to figure out how to retrieve data from a temporary table created on a Postgres database using dplyr. The following code works (I am able to create a temp table using R, and retrieve those results).
flights.db <- src_postgres(dbname = dbname, host = host, port = port,
user = user, password=pwd)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, host = host, port = port, dbname = dbname, user = user, password = pwd)
## Writes the SQL code to create a temporary table on the Postgres Database
sql_tmp_create <- paste0('create temp table tmptblaa as
select * from connections
where \"Carrier\" = \'AA\' and \"Year\" = \'2015\' ')
## Executes the code
dbSendQuery(con, sql_tmp_create)
## Return 10 results from temporary table on Postgres
dbGetQuery(con, 'select * from tmptblaa limit 10')
However, this does not work for me, and I receive an error that the table does not exist:
flights <-tbl(flights.db, "tmptblaa")
Any ideas what I could be doing wrong? For more context, this is to improve the efficiency of a Shiny app that I am working on for a school project. Thanks.