python – SQLAlchemy ORDER BY DESCENDING?

python – SQLAlchemy ORDER BY DESCENDING?

Just as an FYI, you can also specify those things as column attributes. For instance, I might have done:

.order_by(model.Entry.amount.desc())

This is handy since it avoids an import, and you can use it on other places such as in a relation definition, etc.

For more information, you can refer this SQLAlchemy 1.4 Documentation

from sqlalchemy import desc
someselect.order_by(desc(table1.mycol))

Usage from @jpmc26

python – SQLAlchemy ORDER BY DESCENDING?

One other thing you might do is:

.order_by(name desc)

This will result in: ORDER BY name desc. The disadvantage here is the explicit column name used in order by.

Leave a Reply

Your email address will not be published.