diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-13 18:21:42 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-13 18:21:42 -0400 |
commit | 1ac57f0b52e3e89097129931d46ebbbb39ee7927 (patch) | |
tree | 548f6e6982fa3501d6b5a5cf7abd1537a5a68a68 /lib/sqlalchemy/sql/compiler.py | |
parent | a29245e247698160172e42e2154180997b81b8ba (diff) | |
download | sqlalchemy-1ac57f0b52e3e89097129931d46ebbbb39ee7927.tar.gz |
- [bug] Repaired common table expression
rendering to function correctly when the
SELECT statement contains UNION or other
compound expressions, courtesy btbuilder.
[ticket:2490]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 05cc70aba..fd7e7d773 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -572,6 +572,10 @@ class SQLCompiler(engine.Compiled): text += (cs._limit is not None or cs._offset is not None) and \ self.limit_clause(cs) or "" + if self.ctes and \ + compound_index==1 and not entry: + text = self._render_cte_clause() + text + self.stack.pop(-1) if asfrom and parens: return "(" + text + ")" @@ -968,12 +972,7 @@ class SQLCompiler(engine.Compiled): if self.ctes and \ compound_index==1 and not entry: - cte_text = self.get_cte_preamble(self.ctes_recursive) + " " - cte_text += ", \n".join( - [txt for txt in self.ctes.values()] - ) - cte_text += "\n " - text = cte_text + text + text = self._render_cte_clause() + text self.stack.pop(-1) @@ -982,6 +981,14 @@ class SQLCompiler(engine.Compiled): else: return text + def _render_cte_clause(self): + cte_text = self.get_cte_preamble(self.ctes_recursive) + " " + cte_text += ", \n".join( + [txt for txt in self.ctes.values()] + ) + cte_text += "\n " + return cte_text + def get_cte_preamble(self, recursive): if recursive: return "WITH RECURSIVE" |