summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index ee96c8c81..81aa62c25 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -574,9 +574,10 @@ class SQLCompiler(engine.Compiled):
return func.clause_expr._compiler_dispatch(self, **kwargs)
def visit_compound_select(self, cs, asfrom=False,
- parens=True, compound_index=1, **kwargs):
+ parens=True, compound_index=0, **kwargs):
entry = self.stack and self.stack[-1] or {}
- self.stack.append({'from':entry.get('from', None), 'iswrapper':True})
+ self.stack.append({'from': entry.get('from', None),
+ 'iswrapper': not entry})
keyword = self.compound_keywords.get(cs.keyword)
@@ -597,7 +598,7 @@ class SQLCompiler(engine.Compiled):
self.limit_clause(cs) or ""
if self.ctes and \
- compound_index == 1 and not entry:
+ compound_index == 0 and not entry:
text = self._render_cte_clause() + text
self.stack.pop(-1)
@@ -1017,7 +1018,7 @@ class SQLCompiler(engine.Compiled):
def visit_select(self, select, asfrom=False, parens=True,
iswrapper=False, fromhints=None,
- compound_index=1,
+ compound_index=0,
positional_names=None, **kwargs):
entry = self.stack and self.stack[-1] or {}
@@ -1033,11 +1034,14 @@ class SQLCompiler(engine.Compiled):
# to outermost if existingfroms: correlate_froms =
# correlate_froms.union(existingfroms)
+ populate_result_map = compound_index == 0 and (
+ not entry or \
+ entry.get('iswrapper', False)
+ )
+
self.stack.append({'from': correlate_froms,
'iswrapper': iswrapper})
- populate_result_map = compound_index == 1 and not entry or \
- entry.get('iswrapper', False)
column_clause_args = {'positional_names': positional_names}
# the actual list of columns to print in the SELECT column list.
@@ -1112,7 +1116,7 @@ class SQLCompiler(engine.Compiled):
text += self.for_update_clause(select)
if self.ctes and \
- compound_index == 1 and not entry:
+ compound_index == 0 and not entry:
text = self._render_cte_clause() + text
self.stack.pop(-1)