从sqlalchemy中的元数据表中选择一列

时间:2013-02-21 12:37:54

标签: python sqlalchemy

我开始使用sqlalchemy,到目前为止我已经

import sqlalchemy

db = sqlalchemy.create_engine('mysql://CONNECTION?charset=utf8&use_unicode=0')
connection = db.connect()
db.echo = True
metadata = sqlalchemy.MetaData(db)

details_file = sqlalchemy.Table('details_file', metadata, autoload=True)

query = details_file.select([details_file.c.Id]).\
        where(details_file.c.RunId == 5859)
res = query.execute()

我尝试的是只选择符合where标准的列Id。 我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

直接使用select构造:

from sqlalchemy import select

select([details_file.c.Id]).where(details_file.c.runid == 5)