From b6e4a16809744255213a4598dc49a9cff9738b0b Mon Sep 17 00:00:00 2001 From: Eric Atkin Date: Thu, 22 Feb 2018 14:16:14 -0500 Subject: Quote cte alias if needed Fixed bug where CTE expressions would not have their name or alias name quoted when the given name is case sensitive or otherwise requires quoting. Pull request courtesy Eric Atkin. Fixes: #4197 Change-Id: Ib8573e82b9a1ca94b50c7c5d73ee98b79465d689 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/426 --- lib/sqlalchemy/sql/compiler.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 560585cab..be41e80c5 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1427,6 +1427,8 @@ class SQLCompiler(Compiled): if asfrom: if cte_alias_name: text = self.preparer.format_alias(cte, cte_alias_name) + if self.preparer._requires_quotes(cte_name): + cte_name = self.preparer.quote(cte_name) text += self.get_render_as_alias_suffix(cte_name) else: return self.preparer.format_alias(cte, cte_name) -- cgit v1.2.1