All Forums Connectivity
vijaynori 1 post Joined 06/12
21 Jun 2012
python / odbc connection to TD

 

Windows setup: tdodbc__windows_i386.14.00.00.04.zip (tdicu, TeraGSS, tdodbc), Python-2.7.3, pyodbc-3.0.3

 

I am able to extract data from using tdxodbc.  The following piece of python code also works fine -- 

 

========

>>> import pyodbc

>>> conn = pyodbc.connect("Driver={Teradata}; DBCName=...; Authentication=LDAP; UID=...; PWD=...; DATABASE=...")

>>> cursor = conn.cursor()

>>> cursor = cursor.execute("select * from diagnosis sample 2")

>>> for row in cursor:

...     print row

...

(Decimal('77657382651'), 'MAIRA', 'MAIRA', datetime.date(1900, 1, 1), datetime.date(9999, 12, 31))

(Decimal('57565640086'), '988', '988', datetime.date(2009, 10, 1), datetime.date(2009, 10, 31))

========

 

 

Linux (RHEL5.3) setup: tdodbc__linux_indep.14.00.00.04-1.tar.gz (tdicu, TeraGSS, tdodbc), Python-2.7.3, pyodbc-3.0.3

 

I am able to extract data from using tdxodbc.  I get the following error using Python:

 

========

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/local/Python-2.7.3/lib/python2.7/decimal.py", line 548, in __new__

    "Invalid literal for Decimal: %r" % value)

  File "/usr/local/Python-2.7.3/lib/python2.7/decimal.py", line 3866, in _raise_error

    raise error(explanation)

decimal.InvalidOperation: Invalid literal for Decimal: u''

========

 

The first column has data type Decimal(38,0) and causes the problem.  If I explicitly exclude the column as part of the select, the data can be extracted just fine.

 

Has anybody been successful in extracting data from TD using Python?  Thanks.

 

 

wer61537 1 post Joined 06/16
09 Jun 2016

Is Driver={Teradata} the correct name for the Teradata driver?  I get "no default driver specified".

NetFx 346 posts Joined 09/06
21 Jun 2016

Windows or Linux?
This might help: http://developer.teradata.com/blog/odbcteam/2016/02/python-with-teradata-odbc
 

You must sign in to leave a comment.