在 Python/Pyodbc 中查询 Teradata 的问题 [英] Issue with querying Teradata in Python/Pyodbc

查看:33
本文介绍了在 Python/Pyodbc 中查询 Teradata 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PyODBC 在 Python 中查询 Teradata 数据库.数据库连接建立正常;然而,当我尝试获取结果时,我遇到了这个错误十进制的无效文字:u''".请帮忙.

I'm trying to query a Teradata database in Python with PyODBC. The connection to database is established alright; however, when I try to fetch result, I ran into this error "Invalid literal for Decimal: u''". Help please.

我使用的是 RHEL6,使用 Python 2.7.3

I am on RHEL6, with Python 2.7.3

这是代码和结果:

import pyodbc

sql = "select * from table"

pyodbc.pooling = False
cnx = pyodbc.connect("DRIVER={Teradata};DBCNAME=host;DATABASE=database;   AUTHENTICATION=LDAP;UID=user;PWD=password", autocommit=True, ANSI=True)
cursor = cnx.cursor()
rows = cursor.execute(sql).fetchone()

<小时>

InvalidOperation                          Traceback (most recent call last)
<ipython-input-25-f2a0c81ca0e4> in <module>()
----> 1 test.fetchone()

/usr/local/lib/python2.7/decimal.pyc in __new__(cls, value, context)
    546                     context = getcontext()
    547                 return context._raise_error(ConversionSyntax,
--> 548                                 "Invalid literal for Decimal: %r" % value)
    549 
    550             if m.group('sign') == "-":

/usr/local/lib/python2.7/decimal.pyc in _raise_error(self, condition, explanation, *args)
   3864         # Errors should only be risked on copies of the context
   3865         # self._ignored_flags = []
-> 3866         raise error(explanation)
   3867 
   3868     def _ignore_all_flags(self):

InvalidOperation: Invalid literal for Decimal: u''

推荐答案

我遇到了这个错误,我发现原因是pyodbc是64位的,而我的teradata驱动是32位.构建新驱动后问题解决使用unixodbc.

I had this error, and I found the cause was that pyodbc was 64 bit, whereas my teradata driver was 32. The problem was solved after building a new driver with unixodbc.

这篇关于在 Python/Pyodbc 中查询 Teradata 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆