我无法找出需要传递给创建引擎语句的正确 ODBC 字符串。
import pyodbc
import pandas as pd
cnxn=pyodbc.connect('DRIVER=/opt/teradata/client/ODBC_64/lib/tdata.so;DBCName=Server;UID=UN;PWD=PW;Database=myDB')
query = "select top 10 * from TABLE"
df = pd.read_sql(query,cnxn)
import urllib
import sqlalchemy
params = urllib.parse.quote_plus('DRIVER=/opt/teradata/client/ODBC_64/lib/tdata.so;DBCName=Server;UID=UN;PWD=PW;Database=myDB')
engine = sqlalchemy.create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)
query = "select top 10 * from TABLE"
df = pd.read_sql_query(query, engine)
我可以使 pyodbc 连接正常工作,但不能使 sqlalchemy 连接正常工作。任何帮助将不胜感激。
我收到此错误:
InterfaceError: (pyodbc.InterfaceError) ('IM001', '[IM001] [unixODBC][Driver Manager]Driver does not support this function (0) (SQLGetInfo)')
#found the answer here. https://downloads.teradata.com/tools/articles/teradata-sqlalchemy-introduction
from sqlalchemy import create_engine
user = 'sqlalc_user'
pasw=user
host = 'hostname'
port = '1025'
# connect
td_engine = create_engine('teradata://'+ user +':' + pasw + '@'+ host + ':22/')
# execute sql
sql = 'select * from dbc.usersV'
result = td_engine.execute(sql)