[sqlalchemy] Re: MySQL, unions and ordering

2008-12-06 Thread Michael Bayer
you'd say, s.alias().select() it makes subqueries which MySQL probably doesn't require. On Dec 5, 2008, at 10:35 PM, Bo Shi wrote: Thanks; the monkeypatch approach works nicely. Using the alias() method will raise AttributeError: 'Alias' object has no attribute '_order_by_clause'

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-06 Thread Bo Shi
Right; my bad - I misread the instructions. On Sat, Dec 6, 2008 at 9:41 AM, Michael Bayer [EMAIL PROTECTED] wrote: you'd say, s.alias().select() it makes subqueries which MySQL probably doesn't require. On Dec 5, 2008, at 10:35 PM, Bo Shi wrote: Thanks; the monkeypatch approach works

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-05 Thread Michael Bayer
try calling self_group() on each select object. On Dec 5, 2008, at 3:55 PM, Bo Shi wrote: Hi all, There appear to be some nuances to using order by statements with set operations like unions in MySQL but the following is allowed*: (SELECT a,b from DBA.tbl ORDER BY b LIMIT 5) UNION ALL

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-05 Thread Bo Shi
Thanks for the quick response! The following does *not* work. Am I making the call incorrectly? sel = union_all(*[q.self_group() for q in querylist]) On Fri, Dec 5, 2008 at 4:08 PM, Michael Bayer [EMAIL PROTECTED] wrote: try calling self_group() on each select object. On Dec 5, 2008,

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-05 Thread Michael Bayer
that's correct. what does it render ? On Dec 5, 2008, at 4:17 PM, Bo Shi wrote: Thanks for the quick response! The following does *not* work. Am I making the call incorrectly? sel = union_all(*[q.self_group() for q in querylist]) On Fri, Dec 5, 2008 at 4:08 PM, Michael Bayer [EMAIL

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-05 Thread Michael Bayer
from sqlalchemy import * s = select([x, y]).select_from(table) print union_all(s.self_group(), s.self_group()).order_by(foo) (SELECT x, y FROM table) UNION ALL (SELECT x, y FROM table) ORDER BY foo On Dec 5, 2008, at 4:17 PM, Bo Shi wrote: Thanks for the quick response! The

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-05 Thread Bo Shi
I had to upgrade to 0.4.7 from 0.4.2, but your sample query works, however, my application of it does not. Sorry I'm being so light on details, I'll try to reproduce with a complete sample versus using snippets of production code. Each select statement is generated like so: sel =

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-05 Thread Michael Bayer
there's logic which is removing the order_by's from the selects, and in that case this is what's blowing away the parenthesis as well. Some databases don't even allow ORDER BY inside of the queries used in a UNION since in the absense of LIMIT/OFFSET, which also is not standard SQL,

[sqlalchemy] Re: MySQL, unions and ordering

2008-12-05 Thread Bo Shi
Thanks; the monkeypatch approach works nicely. Using the alias() method will raise AttributeError: 'Alias' object has no attribute '_order_by_clause' On Fri, Dec 5, 2008 at 7:25 PM, Michael Bayer [EMAIL PROTECTED] wrote: there's logic which is removing the order_by's from the selects,