【问题标题】:connecting teradata from python without terada driver在没有 terada 驱动程序的情况下从 python 连接 teradata
【发布时间】:2021-01-29 15:37:24
【问题描述】:

我正在尝试在不使用 Teradata 驱动程序的情况下连接到 Teradata。所以安装了 teradatasql 包并编写了下面的代码来连接。

import teradatasql
import pandas as pd

with teradatasql.connect(host='abc.abc.net', user='abcabc', password='abce123') as connect;
    query = "select * from abc.emp;"
    df = pd.read_sql(query, connect)
    print (df.head())

在执行上述代码时,我在下面一行收到 Invalid syntax 错误

with teradatasql.connect(host='abc.abc.net', user='abcabc', password='abce123') as connect;

                                                                                        ^

你能帮我编写连接到 teradata 的代码吗

提前致谢。

【问题讨论】:

    标签: python teradata connectivity


    【解决方案1】:

    将分号 (;) 替换为冒号 (:)

    with 的正确语法是:

    with expression [as variable]:
        with-block
    

    在你的情况下:

    with teradatasql.connect(host='abc.abc.net', user='abcabc', password='abce123') as connect:
       query = ...
    
    

    【讨论】:

      猜你喜欢
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      相关资源
      最近更新 更多