小编Nic*_*ico的帖子

在SQLAlchemy中查询视图

我想知道SQLAlchemy是否在查询视图时遇到问题.如果我在服务器上使用普通SQL查询视图,例如:

SELECT * FROM ViewMyTable WHERE index1 = '608_56_56';
Run Code Online (Sandbox Code Playgroud)

我得到了一大堆记录.但是使用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()
Run Code Online (Sandbox Code Playgroud)

python postgresql sqlalchemy

5
推荐指数
1
解决办法
7478
查看次数

标签 统计

postgresql ×1

python ×1

sqlalchemy ×1