SQLAlchemy Kernel: Descending Order

What is the correct way to execute a select statement using ORDER BY foo DESC in the SQLAlchemy kernel? ( core, not ORM! )

I am currently including the direct order_by direction:

 mytable.select(order_by='name DESC') 

... it works (although I don’t like it, since it is a bit β€œhacky”), but SQLAlchemy gives me the following warning:

SAWarning: Unable to resolve link to label "DESC name"; conversion to text () (this warning may be suppressed after 10 cases)
util.ellipses_string (element.element))

(I did not find anything in the document )

+12
source share
2 answers

From the SQLAlchemy docs :

 from sqlalchemy import desc stmt = select([users_table]).order_by(desc(users_table.c.name)) 
+14
source

Sort column by asc / desc

 desc = " " + asc_desc order_by = re.sub('[^0-9a-zA-Z]+', '', order_by) + desc query = query.order_by(text(order_by)) return query 
0
source

All Articles