Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "compound order by" in sqlalchemy

Tags:

sqlalchemy

Suppose there is a SQL statement:

select * from A order by cola

In sqlalchemy, we can use this code:

session.query(A).order_by(asc(cola))

Now I want to use a "compound order by" in SQL:

select * from A order by cola, colb

Then how will I translate it into sqlalchemy code? Can I use:

session.query(A).order_by(asc(cola, colb))

Probably I can't do it like this.

like image 841
flypen Avatar asked Mar 17 '12 14:03

flypen


1 Answers

I find I can do this:

session.query(A).order_by('cola, colb')

Then this problem will be solved.

like image 112
flypen Avatar answered Dec 03 '22 08:12

flypen