从SQL Alchemy打印列名及其值

时间:2018-01-18 09:06:40

标签: python sqlalchemy

如何在python中使用SQLAlchemy打印列名及其值?

例如:我有一个 USER 表,其中包含2个字段 ID & NAME

ID  NAME
1   John
2   Stella

我需要类似于这个mysql查询的东西:select id as User_ID from USER where id = '1';

目前,我使用以下查询来获取值:

meta = MetaData(engine)
users = Table('USER', meta, autoload=True)
selectQuery = select([users.c.ID, users.c.NAME]).where(users.c.ID == '1')

执行上述查询我得到:

('1', 'John')

相反,我需要这个:

ID  NAME
1   John

0 个答案:

没有答案