Skip to content

Instantly share code, notes, and snippets.

@yaodong
Created July 29, 2016 05:35
Show Gist options
  • Save yaodong/6df392e08bc42f284a0d72c8f273e1ec to your computer and use it in GitHub Desktop.
Save yaodong/6df392e08bc42f284a0d72c8f273e1ec to your computer and use it in GitHub Desktop.
query = some_model.query.filter_by(a=b)
count_q = query.statement.with_only_columns([db.func.count()]).order_by(None)
count = query.session.execute(count_q).scalar()
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment