Connecting Python with Teradata using Teradata module
Question: I have installed python 2.7.0 and Teradata module on Windows 7. i am not able
to connect and quyey TD from python.

    
    
    Pip install Teradata
    

Now i want to import teradata module using Python and perform operations like
-

  1. firing queries to teradata and get result set.
  2. check if connection is made to teradata. 3.etc..

Please help me writing code for the same as i am new to Python and there is no
information available with me to connect to teradata.


Answer: 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;
    

