如何使用 sqlalchemy 和 DSN less 连接来连接到 Teradata Server

问题描述 投票:0回答:1

我无法找出需要传递给创建引擎语句的正确 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)')
python pandas sqlalchemy teradata pyodbc
1个回答
0
投票
#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)
© www.soinside.com 2019 - 2024. All rights reserved.