在 SQLAlchemy 中获取所有记录但字段上的某些条件?
Fetch all records but some condition on filed in SQLAlchemy?
我需要select * from new_entry where batch=2018
。
我试过 query.filter(NewEntry.batch==batch).first()
我得到了数据库中的第一条记录,但我需要所有与 batch.What 匹配的列,我可以吗?
由于您使用的是 first(),因此您只会得到第一个结果,要将所有结果作为一个列表,您必须使用 all()
query.filter(NewEntry.batch==batch).all()
我需要select * from new_entry where batch=2018
。
我试过 query.filter(NewEntry.batch==batch).first()
我得到了数据库中的第一条记录,但我需要所有与 batch.What 匹配的列,我可以吗?
由于您使用的是 first(),因此您只会得到第一个结果,要将所有结果作为一个列表,您必须使用 all()
query.filter(NewEntry.batch==batch).all()