Mike, I totally appreciate the help, but it's just not working, for me.
I feel like you've given tons of time on trying to fix this, so if anyone
else wants to step in to hit me with the clue stick, that would be delightful.
More details
db's tried: postgres, sqlite
sqlalchemy version:
Gregg Lind wrote:
session.query(Route.ts,Route.startpoint,Route.target,func.max(Route.hop_id).label('max_hop'))\
.group_by(Route.ts,Route.startpoint,Route.target).subquery()
q =
session.query(Route,sq.c.max_hop).join(sq,sq.c.max_hop==Route.hop_id)
q.all()
join takes tuples
Thank you! That tuple thing was a fail on my part, clearly.
Doing it exactly as you describe still doesn't get things to be, for
lack of a better term, correlated.
This, however, achieves what I want:
session.query(Route,sq.c.max_hop).join((sq,
and_(Route.hop_id==sq.c.max_hop,
Gregg Lind wrote:
I have read over
http://www.sqlalchemy.org/docs/05/ormtutorial.html#using-subqueries
and http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg11439.html,
but I'm having trouble putting the pieces together.
In the demo() below, I want to find the row in the database
On Thu, Jul 23, 2009 at 3:24 PM, Michael Bayermike...@zzzcomputing.com wrote:
im assuming you're using MySQL since the GROUP BY below doesn't
accommodate every column in the subquery (would be rejected by most DBs).
Corrected. It was Sqlite, but good catch.
youll want to query each column
On Jul 23, 2009, at 5:20 PM, Gregg Lind wrote:
How do I implement this join? If I do this:
sq =
session
.query
(Route
.ts
,Route
.startpoint,Route.target,func.max(Route.hop_id).label('max_hop'))
sq = sq.group_by(Route.ts,Route.startpoint,Route.target).subquery()
then:
q =
On Jul 23, 2009, at 8:43 PM, Gregg Lind wrote:
Hm. I appreciate the help, but something is clearly still failing
here.
session.query(Route,*sq.c).join(sq.c.max_hop)
ArgumentError: Can't find any foreign key relationships between
'route' and 'max_hop'
Maybe the filter based solution
Hm. I appreciate the help, but something is clearly still failing here.
session.query(Route,*sq.c).join(sq.c.max_hop)
ArgumentError: Can't find any foreign key relationships between
'route' and 'max_hop'
Maybe the filter based solution is just fine here :)
On Thu, Jul 23, 2009 at 7:29 PM,