I have list of ID from external postgresql database.
A = [1,2,3,4,5,6,7,98,0]
I would to do query to database using SQLAlchemy, but I would
If you do not necessarily need to do this in SQL, you could simply sort the returned list of objects directly in python.
Example (using python's sorted function)
results = session.query(user).filter(user.id.in_(A)).all() results = sorted(results, key=lambda o: A.index(o.id))