我使用的是sqlalchemy 0.8,我只想获取输入的列名,而不是表中的所有列。你知道吗
代码如下:
rec = raw_input("Enter keyword to search: ")
res = session.query(test.__table__).filter(test.fname == rec).first()
data = ','.join(map(str, res)) +","
print data
#saw this here @ SO but not the one I wanted. It displays all of the columns
columns = [m.key for m in data.columns]
print columns
您只需查询所需的列。就像你有个模特
MyModel
你可以做:这将只选择此处提到的所有列。你知道吗
您可以使用select语法。你知道吗
或者,如果仍然希望返回模型对象而不加载某些列,则可以使用deferred column loading。你知道吗
相关问题 更多 >
编程相关推荐