如何在从Teradata提取大型数据集的同时在sqlalchmey中应用多个whereclause

时间:2020-11-05 04:56:48

标签: python-3.x sqlalchemy dask teradatasql

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

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())

但是当我尝试申请时以及在何处出现错误

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

1 个答案:

答案 0 :(得分:-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请求?