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 to sort data in postgresql by A list.
I have read a lot of documentation but cannot find any suggestions how to do that.
So, in final I would to have:
results = session.query(user).limit(20).offset(10).order_by(A)
Cheers
UPDATE:
I found solution, it's not so good as I expected, but works well. Anyway if you know better solution, just let me know!
ids = ','.join([str(i) for i in A])
results = session.query(user).filter(user.id.in_(A)).\
limit(20).offset(10).\
order_by(" position(CONCAT(',',users.id::text,',') in ',{0},'.format(ids)")