Where is avg, sum, max... etc.?

1,096 views
Skip to first unread message

Victor Lin

unread,
Aug 3, 2008, 10:57:42 AM8/3/08
to sqlalchemy
Hi,
I want use some functions of sql such as sum, avg, max...etc.
But I can't find them in the version I am using : 0.5.0Beta1

I saw these in change log of 0.4.4:

- Deprecated Query methods apply_sum(), apply_max(),
apply_min(), apply_avg(). Better methodologies are
coming....

So.... That means, there is no sql function to use yet in this
version?
If not, where they are?

Thanks.

jason kirtland

unread,
Aug 3, 2008, 11:19:06 AM8/3/08
to sqlal...@googlegroups.com

They're generated by the 'func' function:

from sqlalchemy import func
func.avg(...)
func.sum(...)
func.max(...)

'func' can generate any SQL function.

New in 0.5 is the ability to use an ORM query like a select:

session.query(func.avg(Scorecard.score))

That style replaces the apply_* methods.


Victor Lin

unread,
Aug 3, 2008, 11:34:01 AM8/3/08
to sqlalchemy
Thank you, Jason.

But, it seems that there is no document mention this.
Or it is too difficult to find?
Could somebody add them to document, so that other guys can find it
easily.

Thanks.

Michael Bayer

unread,
Aug 3, 2008, 11:41:40 AM8/3/08
to sqlalchemy


On Aug 3, 11:34 am, Victor Lin <Borns...@gmail.com> wrote:
> Thank you, Jason.
>
> But, it seems that there is no document mention this.
> Or it is too difficult to find?
> Could somebody add them to document, so that other guys can find it
> easily.
>


functions are described here:

http://www.sqlalchemy.org/docs/04/sqlexpression.html#sql_everythingelse_functions

the ORM tutorial in 0.5 shows a usage here:

http://www.sqlalchemy.org/docs/05/ormtutorial.html#datamapping_joins_subqueries

there 0.5 migration guide at http://www.sqlalchemy.org/trac/wiki/05Migration
points to a set of source code as a place to find "how to's" for old
things using the newer ways - apply_max and others are illustrated
starting at http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/test/orm/deprecations.py#L129
.
Reply all
Reply to author
Forward
0 new messages