]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed regression dating back to 0.7.9 whereby the name of a CTE might
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Aug 2013 18:46:04 +0000 (14:46 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Aug 2013 18:46:04 +0000 (14:46 -0400)
not be properly quoted if it was referred to in multiple FROM clauses.
Also in 0.8.3, 0.7.11. [ticket:2801]

doc/build/changelog/changelog_07.rst
doc/build/changelog/changelog_08.rst
doc/build/changelog/changelog_09.rst
lib/sqlalchemy/sql/compiler.py
test/sql/test_cte.py

index 3504a5134d7a56c394b8434842a2aaf732c606e2..c6da742b8decdb3d1d6a0271c251533fb17571f4 100644 (file)
@@ -6,6 +6,13 @@
 .. changelog::
     :version: 0.7.11
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 2801
+
+        Fixed regression dating back to 0.7.9 whereby the name of a CTE might
+        not be properly quoted if it was referred to in multiple FROM clauses.
+
     .. change::
         :tags: mysql, bug
         :tickets: 2791
index 952c45662a9360820609b23a550d202f228ee81c..9d7b4b975fb9fd28375388c5d2543d13ab8ce0a2 100644 (file)
@@ -6,6 +6,14 @@
 .. changelog::
     :version: 0.8.3
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 2801
+
+        Fixed regression dating back to 0.7.9 whereby the name of a CTE might
+        not be properly quoted if it was referred to in multiple FROM clauses.
+        Also in 0.7.11.
+
     .. change::
         :tags: bug, examples
 
index 3e755125bf1b3c15da21fb55da9e21829705fcff..cc9954120042cbe03219a603cda8eb1d7828c901 100644 (file)
@@ -6,6 +6,14 @@
 .. changelog::
     :version: 0.9.0
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 2801
+
+        Fixed regression dating back to 0.7.9 whereby the name of a CTE might
+        not be properly quoted if it was referred to in multiple FROM clauses.
+        Also in 0.8.3, 0.7.11.
+
     .. change::
         :tags: bug, mysql
 
index a6e6987c5e585c7c705e8485c3c312fe94b2f0c9..dc3d55039d1cafe704108cc42e5b4aed23b96b3c 100644 (file)
@@ -1049,7 +1049,7 @@ class SQLCompiler(Compiled):
             # we've generated a same-named CTE that we are enclosed in,
             # or this is the same CTE.  just return the name.
             if cte in existing_cte._restates or cte is existing_cte:
-                return cte_name
+                return self.preparer.format_alias(cte, cte_name)
             elif existing_cte in cte._restates:
                 # we've generated a same-named CTE that is
                 # enclosed in us - we take precedence, so
index 5368b9891d057b4b6788d6a5183c64dd67bb6b7c..0f68313759f830391619989065c6bec77f027473 100644 (file)
@@ -312,6 +312,22 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL):
             "FROM regional_sales"
             )
 
+    def test_multi_subq_quote(self):
+        cte = select([literal(1).label("id")]).cte(name='CTE')
+
+        s1 = select([cte.c.id]).alias()
+        s2 = select([cte.c.id]).alias()
+
+        s = select([s1, s2])
+        self.assert_compile(
+            s,
+            'WITH "CTE" AS (SELECT :param_1 AS id) '
+            'SELECT anon_1.id, anon_2.id FROM '
+            '(SELECT "CTE".id AS id FROM "CTE") AS anon_1, '
+            '(SELECT "CTE".id AS id FROM "CTE") AS anon_2'
+        )
+
+
     def test_positional_binds(self):
         orders = table('orders',
             column('order'),