我正在尝试在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.
我做错了什么?
答案 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>)