开发者

SQLAlchemy 0.5.8 Max function

using SQLAlchemy 0.5.8 开发者_JS百科how do you run a max query?

i.e. Select max(id) from some_table


I know this question is specifically about v0.5.8, but for anyone coming here from google 4 years later, func is now in sqlalchemy.sql.expression.

Example:

from sqlalchemy.sql.expression import func

session.query(func.max(Table.column))


from sqlalchemy import func 

session.query(func.max(Table.column)) 


from sqlalchemy import func
max_id = session.query(func.max(Table.column)).scalar()


If you want to, for e.g.

Select max(table_column) from some_table where other_field=10

You can do

from sqlalchemy import func
session.query(func.max(table_column)).filter_by(other_field=10)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜