diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-07-31 18:42:58 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-07-31 18:42:58 -0400 |
commit | 8b0f4d2a92c54cde9fefa8182bbd1bb503071d49 (patch) | |
tree | b7c715f6d4d5c4952901fe3a19dc163ae35b26bc /lib/sqlalchemy/sql/compiler.py | |
parent | 937c098d5a9b11f2707fc7bf57408cd98dae5c4e (diff) | |
download | sqlalchemy-8b0f4d2a92c54cde9fefa8182bbd1bb503071d49.tar.gz |
- Fixed bug in common table expression system where if the CTE were
used only as an ``alias()`` construct, it would not render using the
WITH keyword. Also in 0.8.3, 0.7.11.
[ticket:2783]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 72bebca3d..daed7c50f 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -961,12 +961,17 @@ class SQLCompiler(engine.Compiled): self.ctes_by_name[cte_name] = cte - if cte.cte_alias: - if isinstance(cte.cte_alias, sql._truncated_label): - cte_alias = self._truncated_identifier("alias", cte.cte_alias) - else: - cte_alias = cte.cte_alias - if not cte.cte_alias and cte not in self.ctes: + if cte._cte_alias is not None: + orig_cte = cte._cte_alias + if orig_cte not in self.ctes: + self.visit_cte(orig_cte) + cte_alias_name = cte._cte_alias.name + if isinstance(cte_alias_name, sql._truncated_label): + cte_alias_name = self._truncated_identifier("alias", cte_alias_name) + else: + orig_cte = cte + cte_alias_name = None + if not cte_alias_name and cte not in self.ctes: if cte.recursive: self.ctes_recursive = True text = self.preparer.format_alias(cte, cte_name) @@ -989,9 +994,10 @@ class SQLCompiler(engine.Compiled): self, asfrom=True, **kwargs ) self.ctes[cte] = text + if asfrom: - if cte.cte_alias: - text = self.preparer.format_alias(cte, cte_alias) + if cte_alias_name: + text = self.preparer.format_alias(cte, cte_alias_name) text += " AS " + cte_name else: return self.preparer.format_alias(cte, cte_name) |