On Jan 8, 2012, at 3:16 PM, Yuen Ho Wong wrote:

> Except that LIMIT and OFFSET are present in my query, gnarly isn't
> it ? :P
> 
>    d = label("distance",
> some_complicated_geoalchemy_function_call(columns...))
> 
>    q = session.query(Product, Merchant.location, d)\
>            .join(Merchant, Product.merchant_id == Merchant.id)\
>            .filter(Product.numinstock > 0)\
>            .options(subqueryload_all(Product.origin, Product.style,
> Product.foods, Product.flavors, Product.occasions, Product.moods,
> Product.varieties))
> 
>    q = q.order_by("distance").offset(0).limit(20).all()

LIMIT and OFFSET require an ORDER BY.   Ordering is non-deterministic without 
ORDER BY, so with LIMIT/OFFSET it means your results are non-deterministic as 
well.  

In fact you can't even use LIMIT/OFFSET on some databases without ORDER BY 
present.

Without being able to run this it would appear you just need to order_by(d) 
here.   But the "distance" label should also be rendered into the subqueryload, 
should just work that way too.    Or try 
order_by(func.some_complex_geoalchemy_function(...)).

You can also roll the subqueryload manually (a recipe is at:  
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DisjointEagerLoading ).

If you have further problems please produce a .py file that actually runs - 
what we need here is just "print q" to print the SQL generated by the query, 
doesn't need to actually generate tables.   You can omit all the extraneous 
model objects and column too.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to