Q:

what is the meaning of func.sum(TableName.count)?

I am converting some SQLAlchemy code to Django ORM (...I am new to SQLA).
I have a line that looks like:
db_session.query(func.sum(MyTable.count)).filter_by(...).scalar()

The intention seems to be to generate a simple count, but in examples I found online the more idiomatic way to do that would be:
db_session.query(func.count(MyTable.id))

...does the first line do something different to this, or it's just un-idiomatic?
I thought it might be summing aggregate counts, but there only seems to be the one table involved and no group_by so I don't think so.

A:

func.sum generates a SUM expression, which sums the values.
func.count generates a COUNT epxression, which counts the values.
If you have [1, 2, 3, 4], sum will produce 10, count will produce 4.

