Search code examples
rodbcteradatarodbc

R and odbcDriverConnect() to connect R to teradata


I am trying to connect R to Teradata and am not sure what the input items are to the RODBC::odbcDriverConnect(). There is a teradataR package, but it is only used with R versions 3 and under, which I neither have nor want to switch to. Below is a list of the input parameters to get ODBCDriverConnect to work. "Connection" I believe is most important. I need to get an address for a driver that I don't even know if I have. This is what I need most help with. How do I get a driver for Teradata to connect to R? IT at my work is not sure how to do this. Also, if anyone knows of another way to connect Teradata to R (some other package?), please let me know.

connection = ""
case
 believeNRows = TRUE
 colQuote, tabQuote = colQuote
interpretDot = TRUE
 DBMSencoding = "",
rows_at_time = 100
 readOnlyOptimize = FALSE

Thank you for your help!


Solution

  • I was able to connect R to Teradata using RODBC package. Here is how to do it if you are working on a pc and have a Teradata driver.

    Set up DSN:

    1. Go to: control panel-> administrative tools -> Data Sources (ODBC) -> User DSN tab -> click add-> select Teradata driver (or whatever driver you will be using. ie. could be sql) and press finish.
    2. A box will pop up that needs to be filled in. The following fields need to be filled:

      Name: Can be any name you would like. I chose TeraDataRConnection, for example.
      Name or IP address (DBC name or address): Mine for example is: Databasename.companyname.com. I looked to see how Microsoft access was connected to the database and in doing that, found the DBC address.
      Username: username that you use to connect to database.
      Password: password use to connect to databases (if you don't put your password in here, you will have to manually type it into R every time you connect.

    In R:

    Download RODBC package

    library(RODBC)
    
    ch=odbcConnect("TeraDataRConnection",  uid="USERNAME HERE",pwd="PASSWORD HERE")   
    

    If you want to confim you are connected, you can type in this code to see the tables:

    ListOfTables=sqlTables(ch,tableType="TABLE")
    

    That's it!