Mike Bayer  committed 43c123b

changed aggregate example functions into some that actually make sense

  • Participants
  • Parent commits 96f4425
  • Branches rel_0_3

Comments (0)

Files changed (1)

File doc/build/content/datamapping.txt

 `from_statement()` can also accomodate full `select()` constructs:
-    result = session.query(User).from_statement(
-        select([users],<'e',, group_by=[c for c in users.c])
-    {sql}    ).all()
-    SELECT users.user_id AS users_user_id, users.user_name AS users_user_name, 
-    users.fullname AS users_fullname, users.password AS users_password 
+    {sql}result = session.query(User).from_statement(
+         select([users_table], select([func.max(], scalar=True).label('maxuser') 
+        ).all()
+    SELECT AS users_id, AS users_name, users.fullname AS users_fullname, users.password AS users_password 
     FROM users 
-    WHERE users.user_name>:users_user_name HAVING users.user_name == max(users.user_name)
-    GROUP BY users.user_id, users.user_name, users.fullname, users.password
-    ORDER BY users.oid
-    {'users_user_name': 'e'}
+    WHERE (SELECT max( 
+    FROM users) =
+    {}
 The current criterion represented by a `Query` can be distilled into a count of rows using `count()`.  This is another function which executes SQL immediately, returning an integer result:
 There's also a way to combine scalar results with objects, using `add_column()`.  This is often used for functions and aggregates.  When `add_column()` (or its cousin `add_entity()`, described later) is used, tuples are returned:
-    for r in session.query(User).add_column(func.max([c for c in users_table.c]):
+    for r in session.query(User).add_column(select([func.max(], scalar=True).label('maxuser')):
         print "user:", r[0]
         print "max name:", r[1]