0

我正在尝试使用 dask 和 sqlalchmey 从 teradata 获取更大的数据集。我能够应用单个 whereclause 并能够获取数据。下面是工作代码

td_engine = create_engine(connString)
metadata = MetaData()
t = Table(
    "table",
    metadata,
    Column("c1"),
    schema="schema",
  )
sql = select([t]).where(
        t.c.c1 == 'abc',
    )
)
start = perf_counter()
df = dd.read_sql_table(sql, connString, index_col="c1",schema="schema")
end = perf_counter()
print("Time taken to execute the code {}".format(end - start))
print(df.head())

但是当我尝试申请并在 whereclause 中出现错误时

sql = select([t]).where(
and_(
        t.c.c1 == 'abc',
        t.c.c2 == 'xyz'
    )
)
4

1 回答 1

-1

更多上下文会有所帮助。如果您只需要执行查询,您是否考虑过使用 pandas read_sql 函数并自己编写 SQL 请求?

import teradatasql
import pandas as pd
with teradatasql.connect(host="whomooz",user="guest",password="please") as con:
  df = pd.read_sql("select c1 from mytable where c1='abc' and c2='xyz'", con)
  print(df.head())

或者是否有特定需要使用 pandas 函数来构造 SQL 请求?

于 2020-11-05T18:53:40.260 回答