Connecting Python with Teradata using Teradata module

后端 未结 3 1523
温柔的废话
温柔的废话 2020-12-07 15:10

I have installed python 2.7.0 and Teradata module on Windows 7. I am not able to connect and query TD from python.

pip install Teradata

Now I wa

3条回答
  •  长情又很酷
    2020-12-07 15:34

    Download the Teradata Python module and python pyodbc.pyd from internet. Install using cmd install setup.py.

    Here is the sample script for connecting to teradata and extracting data:

    import teradata
    import pyodbc
    import sys
    
    
    
    udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0",
            logConsole=False)
    
    session = udaExec.connect(method="odbc", dsn="prod32",
            username="PRODRUN", password="PRODRUN");
    
    i = 0
    REJECTED = 'R';
    
    f = file("output.txt","w");sys.stdout=f
    
    cursor =  session.cursor();
    
    ff_remaining = 0;
    
    cnt = cursor.execute("SELECT  SEQ_NO,FRQFBKDC,PNR_RELOC FROM ttemp.ffremaining ORDER BY 1,2,3 ").rowcount;
    rows = cursor.execute("SELECT  SEQ_NO,FRQFBKDC,PNR_RELOC FROM ttemp.ffremaining ORDER BY 1,2,3 ").fetchall();
    
    
    for i in range(cnt):
        ff_remaining = cursor.execute("select count(*) as coun from  ttemp.ffretroq_paxoff where seq_no=? and status <> ?",(rows[i].seq_no,REJECTED)).fetchall();
        print ff_remaining[0].coun, rows[i].seq_no, REJECTED;
    

提交回复
热议问题