SQLAlchemy: an efficient/better select by primary keys?
Posted
by hadrien
on Stack Overflow
See other posts from Stack Overflow
or by hadrien
Published on 2010-04-14T20:04:22Z
Indexed on
2010/04/14
20:43 UTC
Read the original article
Hit count: 180
python
|sqlalchemy
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!
© Stack Overflow or respective owner