diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2021-07-13 15:15:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-07-13 15:15:33 +0000 |
commit | 3f4ee382a71558d4dbc1d37a2bedcecdce3d5461 (patch) | |
tree | c6ca6a07e7b1a7c5b9682de66277c04b0880d28c /lib/sqlalchemy/sql/compiler.py | |
parent | b64ecb03a5411dd5f32e40ac564bec9a886d3672 (diff) | |
parent | a0953bb7095dde805de8c13699b122767ed001b9 (diff) | |
download | sqlalchemy-3f4ee382a71558d4dbc1d37a2bedcecdce3d5461.tar.gz |
Merge "Adjust CTE recrusive col list to accommodate dupe col names"
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 581dad4fb..b9f55b746 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1311,6 +1311,9 @@ class SQLCompiler(Compiled): def visit_grouping(self, grouping, asfrom=False, **kwargs): return "(" + grouping.element._compiler_dispatch(self, **kwargs) + ")" + def visit_select_statement_grouping(self, grouping, **kwargs): + return "(" + grouping.element._compiler_dispatch(self, **kwargs) + ")" + def visit_label_reference( self, element, within_columns_clause=False, **kwargs ): @@ -2562,17 +2565,29 @@ class SQLCompiler(Compiled): col_source = cte.element.selects[0] else: assert False, "cte should only be against SelectBase" + + # TODO: can we get at the .columns_plus_names collection + # that is already (or will be?) generated for the SELECT + # rather than calling twice? recur_cols = [ - c - for c in util.unique_list( - col_source._all_selected_columns - ) - if c is not None + # TODO: proxy_name is not technically safe, + # see test_cte-> + # test_with_recursive_no_name_currently_buggy. not + # clear what should be done with such a case + fallback_label_name or proxy_name + for ( + _, + proxy_name, + fallback_label_name, + c, + repeated, + ) in (col_source._generate_columns_plus_names(True)) + if not repeated ] text += "(%s)" % ( ", ".join( - self.preparer.format_column( + self.preparer.format_label_name( ident, anon_map=self.anon_map ) for ident in recur_cols @@ -5124,6 +5139,20 @@ class IdentifierPreparer(object): return self.quote(name) + def format_label_name( + self, + name, + anon_map=None, + ): + """Prepare a quoted column name.""" + + if anon_map is not None and isinstance( + name, elements._truncated_label + ): + name = name.apply_map(anon_map) + + return self.quote(name) + def format_column( self, column, |