diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2022-02-24 14:42:20 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-02-24 14:42:20 +0000 |
commit | 11333602c0f844e32f12af114f1dfcb160408fcf (patch) | |
tree | 8085956a2f83cbc57d1717dfd6a9eb17e3aa87ac /lib/sqlalchemy/sql | |
parent | 878c37614efd311794aa50467dbb9e3fe972fdff (diff) | |
parent | bef67e58121704a9836e1e5ec2d361cd2086036c (diff) | |
download | sqlalchemy-11333602c0f844e32f12af114f1dfcb160408fcf.tar.gz |
Merge "support add_cte() for TextualSelect" into main
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 4a169f719..b140f9297 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1596,6 +1596,17 @@ class SQLCompiler(Compiled): toplevel = not self.stack entry = self._default_stack_entry if toplevel else self.stack[-1] + new_entry = { + "correlate_froms": set(), + "asfrom_froms": set(), + "selectable": taf, + } + self.stack.append(new_entry) + + if taf._independent_ctes: + for cte in taf._independent_ctes: + cte._compiler_dispatch(self, **kw) + populate_result_map = ( toplevel or ( @@ -1623,7 +1634,12 @@ class SQLCompiler(Compiled): add_to_result_map=self._add_to_result_map, ) - return self.process(taf.element, **kw) + text = self.process(taf.element, **kw) + if self.ctes: + nesting_level = len(self.stack) if not toplevel else None + text = self._render_cte_clause(nesting_level=nesting_level) + text + + return text def visit_null(self, expr, **kw): return "NULL" |