From 6eca02a31f9fdbc7d039a89f6f8ea212fe5121d9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 6 Dec 2008 00:14:50 +0000 Subject: - union() and union_all() will not whack any order_by() that has been applied to the select()s inside. If you union() a select() with order_by() (presumably to support LIMIT/OFFSET), you should also call self_group() on it to apply parenthesis. --- lib/sqlalchemy/sql/expression.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/expression.py') diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 3d66ff21b..0bc7e6a49 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -3033,8 +3033,7 @@ class CompoundSelect(_SelectBaseMixin, FromClause): "have identical numbers of columns; select #%d has %d columns, select #%d has %d" % (1, len(self.selects[0].c), n+1, len(s.c)) ) - if s._order_by_clause: - s = s.order_by(None) + # unions group from left to right, so don't group first select if n: self.selects.append(s.self_group(self)) -- cgit v1.2.1