【发布时间】:2011-01-06 08:02:07
【问题描述】:
我想知道 SQLAlchemy 在查询视图时是否有问题。如果我在服务器上使用普通 SQL 查询视图,例如:
SELECT * FROM ViewMyTable WHERE index1 = '608_56_56';
我得到了一大堆记录。但是使用 SQLAlchemy 我只得到第一个。但在计数是正确的数字。我不知道为什么。
这是我的 SQLAlchemy 代码。
myQuery = Session.query(ViewMyTable)
erg = myQuery.filter(ViewMyTable.index1 == index1.strip())
# Contains the correct number of all entries I found with that query.
totalCount = erg.count()
# Contains only the first entry I found with my query.
ergListe = erg.all()
【问题讨论】:
标签: python postgresql sqlalchemy