internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: tobymao/sqlglot

Issue:
end is not allowed in Databricks, tough it should be ok
```python
import sqlglot as sg
sg.parse("SELECT end from a", "databricks")
```

end is not a keyword in databricks. However the above fails never the less



Discussion:
Might be a bit complicated as Case is supported in Databricks. Low Prio for me
I think we can just add `TokenType.END` to `ID_VAR_TOKENS` in the base parser. I'll take a look soon.

Also, feel free to open a PR for these issues. There are several contributors (me included) that would be happy to help guide you!

Resolving patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -179,6 +179,7 @@ class Parser(metaclass=_Parser):
         TokenType.DIV,
         TokenType.DISTKEY,
         TokenType.DISTSTYLE,
+        TokenType.END,
         TokenType.EXECUTE,
         TokenType.ENGINE,
         TokenType.ESCAPE,


Test patch:
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -689,3 +689,4 @@ ALTER TABLE baa ADD CONSTRAINT boo FOREIGN KEY (x, y) REFERENCES persons ON UPDA
 ALTER TABLE a ADD PRIMARY KEY (x, y) NOT ENFORCED
 ALTER TABLE a ADD FOREIGN KEY (x, y) REFERENCES bla
 CREATE TABLE foo (baz_id INT REFERENCES baz(id) DEFERRABLE)
+SELECT end FROM a
Repository: tobymao/sqlglot

Issue:
Support for QUALIFY 
the following is not recognized:

```python
import sqlglot as sg 

sg.parse("""
select id from b.a a
        qualify row_number() over (partition by br order by sadf desc) = 1
""", "databricks")
```

QUALIFY is supported by databricks and a number of other cool databases (such as duckdb)


Discussion:
I can look at this soon.

Resolving patch:
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py
--- a/sqlglot/dialects/bigquery.py
+++ b/sqlglot/dialects/bigquery.py
@@ -124,7 +124,6 @@ class Tokenizer(tokens.Tokenizer):
             "FLOAT64": TokenType.DOUBLE,
             "INT64": TokenType.BIGINT,
             "NOT DETERMINISTIC": TokenType.VOLATILE,
-            "QUALIFY": TokenType.QUALIFY,
             "UNKNOWN": TokenType.NULL,
         }
         KEYWORDS.pop("DIV")
diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -195,7 +195,6 @@ class Tokenizer(tokens.Tokenizer):
         KEYWORDS = {
             **tokens.Tokenizer.KEYWORDS,
             "EXCLUDE": TokenType.EXCEPT,
-            "QUALIFY": TokenType.QUALIFY,
             "RENAME": TokenType.REPLACE,
             "TIMESTAMP_LTZ": TokenType.TIMESTAMPLTZ,
             "TIMESTAMP_NTZ": TokenType.TIMESTAMP,
diff --git a/sqlglot/tokens.py b/sqlglot/tokens.py
--- a/sqlglot/tokens.py
+++ b/sqlglot/tokens.py
@@ -589,6 +589,7 @@ class Tokenizer(metaclass=_Tokenizer):
         "PRECEDING": TokenType.PRECEDING,
         "PRIMARY KEY": TokenType.PRIMARY_KEY,
         "PROCEDURE": TokenType.PROCEDURE,
+        "QUALIFY": TokenType.QUALIFY,
         "RANGE": TokenType.RANGE,
         "RECURSIVE": TokenType.RECURSIVE,
         "REGEXP": TokenType.RLIKE,


Test patch:
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -690,3 +690,4 @@ ALTER TABLE a ADD PRIMARY KEY (x, y) NOT ENFORCED
 ALTER TABLE a ADD FOREIGN KEY (x, y) REFERENCES bla
 CREATE TABLE foo (baz_id INT REFERENCES baz(id) DEFERRABLE)
 SELECT end FROM a
+SELECT id FROM b.a AS a QUALIFY ROW_NUMBER() OVER (PARTITION BY br ORDER BY sadf DESC) = 1
Repository: tobymao/sqlglot

Issue:
Hive Dialect for 'insert ... partition' error
Here is a good case, the partition state is string '0'. If we change it to int 0, then there is a error.
![image](https://user-images.githubusercontent.com/34465781/215731767-5c164d0f-f83b-41c1-ae05-6d96daf04247.png)

Int 0
![image](https://user-images.githubusercontent.com/34465781/215732091-7a88a752-f850-412e-b193-8fd00600152c.png)
![image](https://user-images.githubusercontent.com/34465781/215732141-f0523e5b-7592-402e-a47e-ed4a3697d857.png)




Discussion:

Resolving patch:
diff --git a/sqlglot/generator.py b/sqlglot/generator.py
--- a/sqlglot/generator.py
+++ b/sqlglot/generator.py
@@ -631,7 +631,7 @@ def national_sql(self, expression: exp.National) -> str:
     def partition_sql(self, expression: exp.Partition) -> str:
         keys = csv(
             *[
-                f"""{prop.name}='{prop.text("value")}'""" if prop.text("value") else prop.name
+                f"{prop.name}={self.sql(prop, 'value')}" if prop.args.get("value") else prop.name
                 for prop in expression.this
             ]
         )
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -1260,7 +1260,7 @@ def _parse_partition(self) -> t.Optional[exp.Expression]:
             return None
 
         def parse_values() -> exp.Property:
-            props = self._parse_csv(self._parse_var_or_string, sep=TokenType.EQ)
+            props = self._parse_csv(self._parse_field, sep=TokenType.EQ)
             return exp.Property(this=seq_get(props, 0), value=seq_get(props, 1))
 
         return self.expression(exp.Partition, this=self._parse_wrapped_csv(parse_values))


Test patch:
diff --git a/tests/dialects/test_hive.py b/tests/dialects/test_hive.py
--- a/tests/dialects/test_hive.py
+++ b/tests/dialects/test_hive.py
@@ -339,6 +339,10 @@ def test_order_by(self):
 
     def test_hive(self):
         self.validate_identity(
+            "INSERT OVERWRITE TABLE zipcodes PARTITION(state='0') VALUES (896, 'US', 'TAMPA', 33607)"
+        )
+        self.validate_identity(
+            "INSERT OVERWRITE TABLE zipcodes PARTITION(state=0) VALUES (896, 'US', 'TAMPA', 33607)"
             "SELECT a, b, SUM(c) FROM tabl AS t GROUP BY a, b GROUPING SETS ((a, b), a)"
         )
         self.validate_identity(
Repository: tobymao/sqlglot

Issue:
SQLite to Postgres single-quote alias conversions
The following query is valid SQLite–

```
SELECT 1 AS 'This is valid';
```

The transpiler from SQLite to Postgres strips the quotes and produces a Postgres syntax error:

```
sqlglot.transpile("SELECT 1 AS 'This is valid in sqlite'", read='sqlite', write='postgres')
> ['SELECT 1 AS This is valid in sqlite']
```

This is unfortunately not valid Postgres.

```
postgres=# SELECT 1 AS This is valid in sqlite;
ERROR:  syntax error at or near "is"
LINE 1: SELECT 1 AS This is valid in sqlite;
```

Correct output would be `SELECT 1 AS "This is valid in sqlite"`


Discussion:

Resolving patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -3156,7 +3156,9 @@ def _parse_id_var(
                 prefix += self._prev.text
 
         if (any_token and self._advance_any()) or self._match_set(tokens or self.ID_VAR_TOKENS):
-            return exp.Identifier(this=prefix + self._prev.text, quoted=False)
+            quoted = self._prev.token_type == TokenType.STRING
+            return exp.Identifier(this=prefix + self._prev.text, quoted=quoted)
+
         return None
 
     def _parse_string(self) -> t.Optional[exp.Expression]:


Test patch:
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -161,6 +161,7 @@ SELECT 1 FROM test
 SELECT * FROM a, b, (SELECT 1) AS c
 SELECT a FROM test
 SELECT 1 AS filter
+SELECT 1 AS "quoted alias"
 SELECT SUM(x) AS filter
 SELECT 1 AS range FROM test
 SELECT 1 AS count FROM test
Repository: tobymao/sqlglot

Issue:
Table alias in EXCEPT statement
The following produces a parse error, but is valid (at least in Databricks - not sure of other dialects).

`SELECT A.*
EXCEPT (A.COL_1)
FROM TABLE_1 A`

Error message:
![image](https://user-images.githubusercontent.com/32236862/217645405-344385d0-38d8-4684-8af0-516c7dbd20b6.png)


For clarity, the following is not valid:
`SELECT A.*, B.* EXCEPT (A.COL_1) ...`


Discussion:

Resolving patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -3296,8 +3296,8 @@ def _parse_except(self) -> t.Optional[t.List[t.Optional[exp.Expression]]]:
         if not self._match(TokenType.EXCEPT):
             return None
         if self._match(TokenType.L_PAREN, advance=False):
-            return self._parse_wrapped_id_vars()
-        return self._parse_csv(self._parse_id_var)
+            return self._parse_wrapped_csv(self._parse_column)
+        return self._parse_csv(self._parse_column)
 
     def _parse_replace(self) -> t.Optional[t.List[t.Optional[exp.Expression]]]:
         if not self._match(TokenType.REPLACE):


Test patch:
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -394,6 +394,7 @@ SELECT * EXCEPT (a, b) REPLACE (a AS b, b AS C)
 SELECT * EXCEPT (a, b) REPLACE (a AS b, b AS C) FROM y
 SELECT a.* EXCEPT (a, b), b.* REPLACE (a AS b, b AS C)
 SELECT a.* EXCEPT (a, b), b.* REPLACE (a AS b, b AS C) FROM x
+SELECT A.* EXCEPT (A.COL_1) FROM TABLE_1 AS A
 SELECT zoo, animals FROM (VALUES ('oakland', ARRAY('a', 'b')), ('sf', ARRAY('b', 'c'))) AS t(zoo, animals)
 SELECT zoo, animals FROM UNNEST(ARRAY(STRUCT('oakland' AS zoo, ARRAY('a', 'b') AS animals), STRUCT('sf' AS zoo, ARRAY('b', 'c') AS animals))) AS t(zoo, animals)
 WITH a AS (SELECT 1) SELECT 1 UNION ALL SELECT 2
diff --git a/tests/fixtures/pretty.sql b/tests/fixtures/pretty.sql
--- a/tests/fixtures/pretty.sql
+++ b/tests/fixtures/pretty.sql
@@ -342,3 +342,8 @@ SELECT
   basket_index
 FROM table_data
 CROSS JOIN UNNEST(fruit_basket) AS fruit WITH OFFSET AS basket_index;
+SELECT A.* EXCEPT A.COL_1, A.COL_2 FROM TABLE_1 A;
+SELECT
+  A.*
+  EXCEPT (A.COL_1, A.COL_2)
+FROM TABLE_1 AS A;
Repository: tobymao/sqlglot

Issue:
transpiling from snowflake to snowflake converts DAYOFWEEK to nonexistent DAY_OF_WEEK
works in snowflake: `select dayofweek( '2016-01-02T23:39:20.123-07:00'::timestamp)`

in sqlglot 11.0.0, python 3.10.4:

```python
import sqlglot

# converts dayofweek to nonexistent DAY_OF_WEEK
print(sqlglot.transpile("select dayofweek( '2016-01-02T23:39:20.123-07:00'::timestamp)", read='snowflake', write='snowflake'))
```




Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -222,6 +222,7 @@ class Generator(generator.Generator):
             exp.TimeToUnix: lambda self, e: f"EXTRACT(epoch_second FROM {self.sql(e, 'this')})",
             exp.Trim: lambda self, e: f"TRIM({self.format_args(e.this, e.expression)})",
             exp.UnixToTime: _unix_to_time_sql,
+            exp.DayOfWeek: rename_func("DAYOFWEEK"),
         }
 
         TYPE_MAPPING = {


Test patch:
diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -8,6 +8,12 @@ class TestSnowflake(Validator):
     def test_snowflake(self):
         self.validate_identity("SELECT REGEXP_LIKE(a, b, c)")
 
+        self.validate_all(
+            "SELECT DAYOFWEEK('2016-01-02T23:39:20.123-07:00'::TIMESTAMP)",
+            write={
+                "snowflake": "SELECT DAYOFWEEK(CAST('2016-01-02T23:39:20.123-07:00' AS TIMESTAMPNTZ))",
+            },
+        )
         self.validate_all(
             "SELECT * FROM xxx WHERE col ilike '%Don''t%'",
             write={
Repository: tobymao/sqlglot

Issue:
snowflake: transpiling "COPY INTO" raises ParseError
In snowflake I can do `COPY INTO NEW_TABLE ( "foo", "bar")  FROM ( SELECT $1, $2, $3, $4 FROM @%old_table)`.  In sqlglot I get `ParseError`:

```python
import sqlglot

print(sqlglot.transpile('COPY INTO NEW_TABLE ( "foo", "bar")  FROM ( SELECT $1, $2, $3, $4 FROM @%old_table)', 'snowflake'))
```

I'm on sqlglot 11.0.0, python 3.10.4.


Discussion:
I can take a look at this soon.

Resolving patch:
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py
--- a/sqlglot/dialects/redshift.py
+++ b/sqlglot/dialects/redshift.py
@@ -41,7 +41,6 @@ class Tokenizer(Postgres.Tokenizer):
 
         KEYWORDS = {
             **Postgres.Tokenizer.KEYWORDS,  # type: ignore
-            "COPY": TokenType.COMMAND,
             "ENCODE": TokenType.ENCODE,
             "GEOMETRY": TokenType.GEOMETRY,
             "GEOGRAPHY": TokenType.GEOGRAPHY,
diff --git a/sqlglot/tokens.py b/sqlglot/tokens.py
--- a/sqlglot/tokens.py
+++ b/sqlglot/tokens.py
@@ -697,6 +697,7 @@ class Tokenizer(metaclass=_Tokenizer):
         "ALTER VIEW": TokenType.COMMAND,
         "ANALYZE": TokenType.COMMAND,
         "CALL": TokenType.COMMAND,
+        "COPY": TokenType.COMMAND,
         "EXPLAIN": TokenType.COMMAND,
         "OPTIMIZE": TokenType.COMMAND,
         "PREPARE": TokenType.COMMAND,


Test patch:
diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -8,6 +8,9 @@ class TestSnowflake(Validator):
     def test_snowflake(self):
         self.validate_identity("SELECT REGEXP_LIKE(a, b, c)")
         self.validate_identity("CREATE TABLE foo (bar FLOAT AUTOINCREMENT START 0 INCREMENT 1)")
+        self.validate_identity(
+            'COPY INTO NEW_TABLE ("foo", "bar") FROM (SELECT $1, $2, $3, $4 FROM @%old_table)'
+        )
 
         self.validate_all(
             "CREATE OR REPLACE TEMPORARY TABLE x (y NUMBER IDENTITY(0, 1))",
Repository: tobymao/sqlglot

Issue:
Missing snowflake functions
Transpiling the follow query from `Snowflake` to `SQLite` returns the same query even though `div0` and `nullifzero` both are unavailable in `SQLite`.

Input
```
sql_query = """
select
    div0(foo,bar) as foobar,
    zeroifnull(baz) as baz
"""
sqlglot.transpile(sql_query, read="snowflake", write="sqlite")
```
Output
`['SELECT DIV0(foo, bar) AS foobar, ZEROIFNULL(baz) AS baz']
`





Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -106,6 +106,20 @@ def _parse_date_part(self):
     return self.expression(exp.Extract, this=this, expression=expression)
 
 
+# https://docs.snowflake.com/en/sql-reference/functions/div0
+def _div0_to_if(args):
+    cond = exp.EQ(this=seq_get(args, 1), expression=exp.Literal.number(0))
+    true = exp.Literal.number(0)
+    false = exp.Div(this=seq_get(args, 0), expression=seq_get(args, 1))
+    return exp.If(this=cond, true=true, false=false)
+
+
+# https://docs.snowflake.com/en/sql-reference/functions/zeroifnull
+def _zeroifnull_to_if(args):
+    cond = exp.EQ(this=seq_get(args, 0), expression=exp.Null())
+    return exp.If(this=cond, true=exp.Literal.number(0), false=seq_get(args, 0))
+
+
 def _datatype_sql(self, expression):
     if expression.this == exp.DataType.Type.ARRAY:
         return "ARRAY"
@@ -157,6 +171,7 @@ class Parser(parser.Parser):
                 unit=exp.Literal.string(seq_get(args, 0).name),  # type: ignore
                 this=seq_get(args, 1),
             ),
+            "DIV0": _div0_to_if,
             "IFF": exp.If.from_arg_list,
             "TO_ARRAY": exp.Array.from_arg_list,
             "TO_TIMESTAMP": _snowflake_to_timestamp,
@@ -164,6 +179,7 @@ class Parser(parser.Parser):
             "RLIKE": exp.RegexpLike.from_arg_list,
             "DECODE": exp.Matches.from_arg_list,
             "OBJECT_CONSTRUCT": parser.parse_var_map,
+            "ZEROIFNULL": _zeroifnull_to_if,
         }
 
         FUNCTION_PARSERS = {


Test patch:
diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -16,6 +16,17 @@ def test_snowflake(self):
             'COPY INTO NEW_TABLE ("foo", "bar") FROM (SELECT $1, $2, $3, $4 FROM @%old_table)'
         )
 
+        self.validate_all(
+            "DIV0(foo, bar)",
+            write={
+                "snowflake": "IFF(bar = 0, 0, foo / bar)",
+                "sqlite": "CASE WHEN bar = 0 THEN 0 ELSE foo / bar END",
+                "presto": "IF(bar = 0, 0, foo / bar)",
+                "spark": "IF(bar = 0, 0, foo / bar)",
+                "hive": "IF(bar = 0, 0, foo / bar)",
+                "duckdb": "CASE WHEN bar = 0 THEN 0 ELSE foo / bar END",
+            },
+        )
         self.validate_all(
             "CREATE OR REPLACE TEMPORARY TABLE x (y NUMBER IDENTITY(0, 1))",
             write={
Repository: tobymao/sqlglot

Issue:
type `TIMESTAMPTZ` doesn't exist in sparksql
sqlglot transpiles a trino type like `timestamp(6) with time zone` as the hive type `TIMESTAMPTZ` for spark, which isn't a spark type.  I'd be happy to submit a PR if there's advice about how to address this.

```
>>> sqlglot.transpile('select cast(created as timestamp(6) with time zone) created from some_table', read="trino", write="spark")
['SELECT CAST(created AS TIMESTAMPTZ) AS created FROM some_table']
```


Discussion:
i assume we'd just drop it?
@joshmarcus let me know if you plan to tackle this, otherwise I'll take a look soon.

Resolving patch:
diff --git a/sqlglot/dialects/hive.py b/sqlglot/dialects/hive.py
--- a/sqlglot/dialects/hive.py
+++ b/sqlglot/dialects/hive.py
@@ -263,6 +263,7 @@ class Generator(generator.Generator):
             exp.DataType.Type.TEXT: "STRING",
             exp.DataType.Type.DATETIME: "TIMESTAMP",
             exp.DataType.Type.VARBINARY: "BINARY",
+            exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
         }
 
         TRANSFORMS = {


Test patch:
diff --git a/tests/dialects/test_presto.py b/tests/dialects/test_presto.py
--- a/tests/dialects/test_presto.py
+++ b/tests/dialects/test_presto.py
@@ -63,8 +63,8 @@ def test_cast(self):
                 "bigquery": "CAST(x AS TIMESTAMPTZ)",
                 "duckdb": "CAST(x AS TIMESTAMPTZ(9))",
                 "presto": "CAST(x AS TIMESTAMP(9) WITH TIME ZONE)",
-                "hive": "CAST(x AS TIMESTAMPTZ)",
-                "spark": "CAST(x AS TIMESTAMPTZ)",
+                "hive": "CAST(x AS TIMESTAMP)",
+                "spark": "CAST(x AS TIMESTAMP)",
             },
         )
 
diff --git a/tests/dialects/test_spark.py b/tests/dialects/test_spark.py
--- a/tests/dialects/test_spark.py
+++ b/tests/dialects/test_spark.py
@@ -213,6 +213,9 @@ def test_spark(self):
         self.validate_identity("TRIM(LEADING 'SL' FROM 'SSparkSQLS')")
         self.validate_identity("TRIM(TRAILING 'SL' FROM 'SSparkSQLS')")
 
+        self.validate_all(
+            "CAST(x AS TIMESTAMP)", read={"trino": "CAST(x AS TIMESTAMP(6) WITH TIME ZONE)"}
+        )
         self.validate_all(
             "SELECT DATE_ADD(my_date_column, 1)",
             write={
Repository: tobymao/sqlglot

Issue:
Parsing of ClickHouse multi-level quantiles fails
The ClickHouse SQL expression `quantiles(level1, level2, …)(x)` cannot be parsed if there are more than 2 levels:

```python
>>> sqlglot.parse("SELECT quantiles(0.1, 0.2, 0.3)(a)", read="clickhouse")
sqlglot.errors.ParseError: The number of provided arguments (3) is greater than the maximum number of supported arguments (2). Line 1, Col: 34.
  SELECT quantiles(0.1, 0.2, 0.3)(a)
```

while `SELECT quantiles(0.1)(a)` and `SELECT quantiles(0.1, 0.2)(a)` can be parsed just fine.


Discussion:

Resolving patch:
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -3681,6 +3681,7 @@ class Quantile(AggFunc):
 # https://clickhouse.com/docs/en/sql-reference/aggregate-functions/reference/quantiles/#quantiles
 class Quantiles(AggFunc):
     arg_types = {"parameters": True, "expressions": True}
+    is_var_len_args = True
 
 
 class QuantileIf(AggFunc):


Test patch:
diff --git a/tests/dialects/test_clickhouse.py b/tests/dialects/test_clickhouse.py
--- a/tests/dialects/test_clickhouse.py
+++ b/tests/dialects/test_clickhouse.py
@@ -16,6 +16,7 @@ def test_clickhouse(self):
         self.validate_identity("SELECT * FROM foo ANY JOIN bla")
         self.validate_identity("SELECT quantile(0.5)(a)")
         self.validate_identity("SELECT quantiles(0.5)(a) AS x FROM t")
+        self.validate_identity("SELECT quantiles(0.1, 0.2, 0.3)(a)")
         self.validate_identity("SELECT * FROM foo WHERE x GLOBAL IN (SELECT * FROM bar)")
         self.validate_identity("position(haystack, needle)")
         self.validate_identity("position(haystack, needle, position)")
Repository: tobymao/sqlglot

Issue:
Error on parsing SHOW statement with '.' (eg show index from schema_name.table_name)
SQLGlot is throwing an error when I try to "show index from schema_name.table_name" (I am using MySQL as the dialect), due to the period ('.') in the SQL statement. For example "show columns from information_schema.tables" - it is no issue for SELECT statements but possibly for others.

Apologies this is my first time participating on GitHub - if the above isn't specific/clear enough or I can provide any more detail please let me know.

Thanks
James


Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/mysql.py b/sqlglot/dialects/mysql.py
--- a/sqlglot/dialects/mysql.py
+++ b/sqlglot/dialects/mysql.py
@@ -303,7 +303,13 @@ def _parse_show_mysql(self, this, target=False, full=None, global_=None):
                 db = None
             else:
                 position = None
-                db = self._parse_id_var() if self._match_text_seq("FROM") else None
+                db = None
+
+                if self._match(TokenType.FROM):
+                    db = self._parse_id_var()
+                elif self._match(TokenType.DOT):
+                    db = target_id
+                    target_id = self._parse_id_var()
 
             channel = self._parse_id_var() if self._match_text_seq("FOR", "CHANNEL") else None
 


Test patch:
diff --git a/tests/dialects/test_mysql.py b/tests/dialects/test_mysql.py
--- a/tests/dialects/test_mysql.py
+++ b/tests/dialects/test_mysql.py
@@ -424,6 +424,10 @@ def test_show_index(self):
         show = self.validate_identity("SHOW INDEX FROM foo FROM bar")
         self.assertEqual(show.text("db"), "bar")
 
+        self.validate_all(
+            "SHOW INDEX FROM bar.foo", write={"mysql": "SHOW INDEX FROM foo FROM bar"}
+        )
+
     def test_show_db_like_or_where_sql(self):
         for key in [
             "OPEN TABLES",