Repository: kayak/pypika
Pull request #516 (2020-11-04 14:43:31)

Fix OracleQuery Dialect Quote Char
Oracle SQL query breaks when double quoted

A quoted identifier begins and ends with double quotation marks (").
If you name a schema object using a quoted identifier,
then you must use the double quotation marks whenever you refer to that object.
Thus it makes sense that the user will double quote the identifier
him/herself.

A nonquoted identifier is not surrounded by any punctuation.

See https://docs.oracle.com/database/121/SQLRF/sql_elements008.htm

Addresses https://github.com/kayak/pypika/issues/394#issuecomment-616012215
Addresses #298 for OracleQuery

coveralls: 
[![Coverage Status](https://coveralls.io/builds/34710296/badge)](https://coveralls.io/builds/34710296)

Coverage increased (+0.001%) to 98.219% when pulling **3379aeab2d0e714befd49b0313fefdc9acee6a01 on noambloom:bugfix_oracle_query_quote_char** into **82d08770301449ce3ddb8d7c1fe3357f3d3bda34 on kayak:master**.


Patch:
diff --git a/pypika/dialects.py b/pypika/dialects.py
index dbc72f4..84b56d9 100644
--- a/pypika/dialects.py
+++ b/pypika/dialects.py
@@ -270,6 +270,8 @@ class VerticaQuery(Query):
 
 
 class OracleQueryBuilder(QueryBuilder):
+    QUOTE_CHAR = None
+
     def __init__(self, **kwargs: Any) -> None:
         super().__init__(dialect=Dialects.ORACLE, **kwargs)
 


Test patch:
diff --git a/pypika/tests/test_selects.py b/pypika/tests/test_selects.py
index c955199..7f155d8 100644
--- a/pypika/tests/test_selects.py
+++ b/pypika/tests/test_selects.py
@@ -272,10 +272,10 @@ class SelectTests(unittest.TestCase):
 
         self.assertEqual('SELECT "foo","bar" FROM "abc"', str(q))
 
-    def test_oracle_query_uses_double_quote_chars(self):
+    def test_oracle_query_uses_no_quote_chars(self):
         q = OracleQuery.from_("abc").select("foo", "bar")
 
-        self.assertEqual('SELECT "foo","bar" FROM "abc"', str(q))
+        self.assertEqual('SELECT foo,bar FROM abc', str(q))
 
     def test_postgresql_query_uses_double_quote_chars(self):
         q = PostgreSQLQuery.from_("abc").select("foo", "bar")
@@ -530,12 +530,17 @@ class GroupByTests(unittest.TestCase):
             q.get_sql(groupby_alias=False),
         )
 
-    def test_groupby__no_alias_platforms(self):
+    def test_groupby__no_alias_mssql(self):
         bar = self.t.bar.as_("bar01")
-        for query_cls in [MSSQLQuery, OracleQuery]:
-            q = query_cls.from_(self.t).select(fn.Sum(self.t.foo), bar).groupby(bar)
+        q = MSSQLQuery.from_(self.t).select(fn.Sum(self.t.foo), bar).groupby(bar)
 
-            self.assertEqual('SELECT SUM("foo"),"bar" "bar01" FROM "abc" GROUP BY "bar"', str(q))
+        self.assertEqual('SELECT SUM("foo"),"bar" "bar01" FROM "abc" GROUP BY "bar"', str(q))
+
+    def test_groupby__no_alias_oracle(self):
+        bar = self.t.bar.as_("bar01")
+        q = OracleQuery.from_(self.t).select(fn.Sum(self.t.foo), bar).groupby(bar)
+
+        self.assertEqual('SELECT SUM(foo),bar bar01 FROM abc GROUP BY bar', str(q))
 
     def test_groupby__alias_platforms(self):
         bar = self.t.bar.as_("bar01")
@@ -609,10 +614,10 @@ class GroupByTests(unittest.TestCase):
 
         self.assertEqual('SELECT "foo" FROM "abc" GROUP BY "foo"', str(q))
 
-    def test_oracle_query_uses_double_quote_chars(self):
+    def test_oracle_query_uses_no_quote_chars(self):
         q = OracleQuery.from_(self.t).groupby(self.t.foo).select(self.t.foo)
 
-        self.assertEqual('SELECT "foo" FROM "abc" GROUP BY "foo"', str(q))
+        self.assertEqual('SELECT foo FROM abc GROUP BY foo', str(q))
 
     def test_postgres_query_uses_double_quote_chars(self):
         q = PostgreSQLQuery.from_(self.t).groupby(self.t.foo).select(self.t.foo)
@@ -710,14 +715,14 @@ class HavingTests(unittest.TestCase):
         )
         self.assertEqual('SELECT "foo" FROM "abc" GROUP BY "foo" HAVING "buz"=\'fiz\'', str(q))
 
-    def test_oracle_query_uses_double_quote_chars(self):
+    def test_oracle_query_uses_no_quote_chars(self):
         q = (
             OracleQuery.from_(self.table_abc)
             .select(self.table_abc.foo)
             .groupby(self.table_abc.foo)
             .having(self.table_abc.buz == "fiz")
         )
-        self.assertEqual('SELECT "foo" FROM "abc" GROUP BY "foo" HAVING "buz"=\'fiz\'', str(q))
+        self.assertEqual('SELECT foo FROM abc GROUP BY foo HAVING buz=\'fiz\'', str(q))
 
     def test_postgres_query_uses_double_quote_chars(self):
         q = (