我想用PyODBC查詢Python中的Teradata數據庫。 與數據庫的連接建立好了;然而,當我嘗試獲取結果時,我遇到了這個錯誤「Decimal的無效文字:u''」。請幫助。在Python/Pyodbc中查詢Teradata問題
我在RHEL6,與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''
看起來像驅動程序正在期待一個固定點的數字,並得到一個空字符串。你的表模式是什麼樣的?它應該返回哪一行? – cmd
感謝您的提問 - 它幫助我在Python腳本中設置Teradata數據庫連接,需要與結果集一起工作:)。 – Jubbles