从表中选择特定列时出现SQLAlchemy错误

时间:2015-03-05 05:39:10

标签: python sqlalchemy

我正在尝试在SQLAlchemy中选择特定列:

from sqlalchemy import create_engine, MetaData, Table    

engine = create_engine('sqlite:///client.db')
metadata = MetaData(bind=engine)

lc = Table('lc', metadata, autoload=True)

cached = lc.select([lc.c.start, lc.c.end]).execute()

当我尝试运行上面的代码时,我收到此错误:

    "SQL expression object or string expected."
sqlalchemy.exc.ArgumentError: SQL expression object or string expected.

我做错了什么?

1 个答案:

答案 0 :(得分:1)

Table.select只接受where子句。对于特定列,您应使用sqlalchemy.sql.expression.select

from sqlalchemy import select

q = select((lc.c.start, lc.c.end), lc.c.start==<date>)