meta.Session.query(model.History).from_statement(
"SELECT history.*
FROM
(
SELECT max(history.history_id) AS history_id FROM history GROUP BY
history.many_id
)
as max_history join history
ON history.history_id = max_history.history_id and history.action_id
in (foo, ba")"
).all()
Which works but I can't figure how to change the sql to use
sqlalchemy.
The main gotcha is getting the join to work in the subquery.
max_history doesn't have a history_id method. Looking through the
docs.
Half way down the page. The from_statement has something similar but
only returns a single record where I need multiple records. Also in
the example the column is accessed through the c method. When I try
the same no columns are attached to the c method.
Would this indicate that I've done something wrong in the schema? I'm
using 0.4.8 and 0.5.1 on another box.
Hope someone can help me. Thanks
fintan
Michael Bayer
unread,
Apr 24, 2009, 9:46:13 AM4/24/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sqlal...@googlegroups.com
s =
select
([func
.max
(history
.c
.history_id
).label('history_id')]).group_by(history.c.many_id).alias('max_history')