SQLAlchemy: an efficient/better select by primary keys?
- by hadrien
Yet another newbie question..
Let's say I have an user table in declarative mode:
class User(Base):
__tablename__ = 'user'
id = Column(u'id', Integer(), primary_key=True)
name = Column(u'name', String(50))
When I have a list of users identifiers, I fetch them from db with:
user_ids = [1, 2, 3, 4, 5]
users = Session.query(User).filter(User.id.in_(user_ids)).all()
I dislike using in_ because I think I learned it has bad performance on indexed fields
(is that true/false?).
Anyway, is there a better way doing that query?
Thanks!