Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RODBC: merge tables from different databases (channel)

Tags:

sql

r

sqldf

rodbc

I'm using RODBC package to connect to Oracle databases from R but I didn't succeed in merging tables from different databases without "downloading" the tables (I don't want to download them as they are too big!). I'd like to use something like:

DBa=odbcConnect(dsn="DatabaseA",uid="uid",pwd="pwd",readOnly="True")
DBb=odbcConnect(dsn="DatabaseB",uid="uid",pwd="pwd",readOnly="True")
sqldf("select a.year, sum(b.var) as sumVar
       from sqlFetch(DBa,'tableA') a
            sqlFetch(DBb,'tableB') b
       where a.ID=b.ID
       group by a.year")

If someone has an idea, it would be really helpful! Many thanks in advance.

Lionel

like image 730
user3062082 Avatar asked Nov 12 '22 17:11

user3062082


1 Answers

This question is similar to the question here. The answer seems to be that RODBC cannot access two different databases in a single query, using sqlQuery(...), because the connection (channel) is database-specific. So either

(1) do it using downloads (as in your code), or 
(2) have your DBA put both tables in a single database, or 
(3) use something other than R. 
like image 184
jlhoward Avatar answered Nov 15 '22 07:11

jlhoward