Search code examples
sqlrtemp-tablesrmysql

Temporary tables using RMySQL


Is there a way to create a temporary table using the RMySQL package? If so what is the correct way to do it? In particular I am trying to write a dataframe from my R session to the temporary table. I have several processes running in parallel and I don't want to worry about name conflicts, that's why I want to make them temporary so they are only visible to each individual session. The solution should somehow involve dbWritetable and not dbSendQuery("create temporary table tbl;").

NOTE: I found some stuff on the net that suggests creating a temporary table manually using dbSendQuery(con, "create temporary table x (x int)") and then simply overriding it with dbWriteTable(). This does not work.


Solution

  • For this type of job, I would avoid reinventing the wheel and use

    https://code.google.com/p/sqldf/

    By default, it is for sqlite, but it also works for MySQL (which I never tried). This package is rock-solid and well documented.