Repository: kayak/pypika
Pull request #439 (2020-05-26 15:18:12)

Revert #425 remove alias quotes on Snowflake dialect
This was causing issues when using alias' which contain special characters e.g. $. 

+ @airtonzanon @Shawe82


Patch:
diff --git a/pypika/__init__.py b/pypika/__init__.py
index e20dca7..0992199 100644
--- a/pypika/__init__.py
+++ b/pypika/__init__.py
@@ -94,4 +94,4 @@ from pypika.utils import (
 
 __author__ = "Timothy Heys"
 __email__ = "theys@kayak.com"
-__version__ = "0.37.6"
+__version__ = "0.37.5"
diff --git a/pypika/dialects.py b/pypika/dialects.py
index df3fb3f..65ef870 100644
--- a/pypika/dialects.py
+++ b/pypika/dialects.py
@@ -26,6 +26,7 @@ from pypika.utils import (
 
 class SnowFlakeQueryBuilder(QueryBuilder):
     QUOTE_CHAR = None
+    ALIAS_QUOTE_CHAR = '"'
 
     def __init__(self, **kwargs: Any) -> None:
         super().__init__(
diff --git a/pypika/terms.py b/pypika/terms.py
index f16143e..147dde9 100644
--- a/pypika/terms.py
+++ b/pypika/terms.py
@@ -1156,7 +1156,7 @@ class Function(Criterion):
         return "{name}({args}{special})".format(
               name=self.name,
               args=",".join(
-                    p.get_sql(with_alias=False, **kwargs)
+                    p.get_sql(with_alias=True, **kwargs)
                     if hasattr(p, "get_sql")
                     else str(p)
                     for p in self.args
diff --git a/setup.cfg b/setup.cfg
index d9ab4af..30d5b0a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 0.37.6
+current_version = 0.37.5
 commit = True
 tag = True
 


Test patch:
diff --git a/pypika/tests/dialects/test_snowflake.py b/pypika/tests/dialects/test_snowflake.py
index 8ac55a8..49dbb92 100644
--- a/pypika/tests/dialects/test_snowflake.py
+++ b/pypika/tests/dialects/test_snowflake.py
@@ -13,7 +13,7 @@ class QuoteTests(unittest.TestCase):
     def test_use_double_quotes_on_alias_but_not_on_terms(self):
         q = SnowflakeQuery.from_(self.table_abc).select(self.table_abc.a.as_("bar"))
 
-        self.assertEqual('SELECT a bar FROM abc', q.get_sql(with_namespace=True))
+        self.assertEqual('SELECT a "bar" FROM abc', q.get_sql(with_namespace=True))
 
     def test_use_double_quotes_on_alias_but_not_on_terms_with_joins(self):
         foo = self.table_abc.as_("foo")
@@ -28,8 +28,8 @@ class QuoteTests(unittest.TestCase):
 
         self.assertEqual(
             "SELECT foo.a,bar.b "
-            'FROM abc foo '
-            'JOIN efg bar '
+            'FROM abc "foo" '
+            'JOIN efg "bar" '
             "ON foo.fk=bar.id",
             q.get_sql(with_namespace=True),
         )
@@ -45,9 +45,9 @@ class QuoteTests(unittest.TestCase):
         )
 
         self.assertEqual(
-            'SELECT index idx,SUM(value) val '
+            'SELECT index "idx",SUM(value) "val" '
             "FROM abc "
-            'GROUP BY idx '
-            'ORDER BY idx',
+            'GROUP BY "idx" '
+            'ORDER BY "idx"',
             q.get_sql(with_namespace=True),
         )
diff --git a/pypika/tests/test_selects.py b/pypika/tests/test_selects.py
index 2a4569b..1f07317 100644
--- a/pypika/tests/test_selects.py
+++ b/pypika/tests/test_selects.py
@@ -862,20 +862,14 @@ class AliasTests(unittest.TestCase):
         self.assertEqual('SELECT COUNT(*) "foo" FROM "abc"', str(q))
 
     def test_function_using_as_nested(self):
-        """
-        We don't show aliases of fields that are arguments of a function.
-        """
         q = Query.from_(self.t).select(fn.Sqrt(fn.Count("*").as_("foo")).as_("bar"))
 
-        self.assertEqual('SELECT SQRT(COUNT(*)) "bar" FROM "abc"', str(q))
+        self.assertEqual('SELECT SQRT(COUNT(*) "foo") "bar" FROM "abc"', str(q))
 
     def test_functions_using_constructor_param_nested(self):
-        """
-        We don't show aliases of fields that are arguments of a function.
-        """
         q = Query.from_(self.t).select(fn.Sqrt(fn.Count("*", alias="foo"), alias="bar"))
 
-        self.assertEqual('SELECT SQRT(COUNT(*)) "bar" FROM "abc"', str(q))
+        self.assertEqual('SELECT SQRT(COUNT(*) "foo") "bar" FROM "abc"', str(q))
 
     def test_ignored_in_where(self):
         q = Query.from_(self.t).select(self.t.foo).where(self.t.foo.as_("bar") == 1)