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

Issue:
Include support for GEOGRAPHY fields in Snowflake dialect
**Is your feature request related to a problem? Please describe.**
While trying to parse a Snowflake `CREATE OR REPLACE` statement that includes a field of type `GEOGRAPHY`, the parsing fails.

**Describe the solution you'd like**
The parser to recognize `GEOGRAPHY` as a valid Snowflake type.



Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py
--- a/sqlglot/dialects/bigquery.py
+++ b/sqlglot/dialects/bigquery.py
@@ -138,7 +138,6 @@ class Tokenizer(tokens.Tokenizer):
             "BEGIN TRANSACTION": TokenType.BEGIN,
             "CURRENT_DATETIME": TokenType.CURRENT_DATETIME,
             "DECLARE": TokenType.COMMAND,
-            "GEOGRAPHY": TokenType.GEOGRAPHY,
             "FLOAT64": TokenType.DOUBLE,
             "INT64": TokenType.BIGINT,
             "BYTES": TokenType.BINARY,
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py
--- a/sqlglot/dialects/redshift.py
+++ b/sqlglot/dialects/redshift.py
@@ -58,8 +58,6 @@ class Tokenizer(Postgres.Tokenizer):
 
         KEYWORDS = {
             **Postgres.Tokenizer.KEYWORDS,  # type: ignore
-            "GEOMETRY": TokenType.GEOMETRY,
-            "GEOGRAPHY": TokenType.GEOGRAPHY,
             "HLLSKETCH": TokenType.HLLSKETCH,
             "SUPER": TokenType.SUPER,
             "SYSDATE": TokenType.CURRENT_TIMESTAMP,
diff --git a/sqlglot/tokens.py b/sqlglot/tokens.py
--- a/sqlglot/tokens.py
+++ b/sqlglot/tokens.py
@@ -551,6 +551,8 @@ class Tokenizer(metaclass=_Tokenizer):
         "FOREIGN KEY": TokenType.FOREIGN_KEY,
         "FORMAT": TokenType.FORMAT,
         "FROM": TokenType.FROM,
+        "GEOGRAPHY": TokenType.GEOGRAPHY,
+        "GEOMETRY": TokenType.GEOMETRY,
         "GLOB": TokenType.GLOB,
         "GROUP BY": TokenType.GROUP_BY,
         "GROUPING SETS": TokenType.GROUPING_SETS,


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
@@ -6,6 +6,7 @@ class TestSnowflake(Validator):
     dialect = "snowflake"
 
     def test_snowflake(self):
+        self.validate_identity("CAST(x AS GEOMETRY)")
         self.validate_identity("OBJECT_CONSTRUCT(*)")
         self.validate_identity("SELECT TO_DATE('2019-02-28') + INTERVAL '1 day, 1 year'")
         self.validate_identity("SELECT CAST('2021-01-01' AS DATE) + INTERVAL '1 DAY'")
@@ -558,6 +559,7 @@ def test_semi_structured_types(self):
         )
 
     def test_ddl(self):
+        self.validate_identity("CREATE TABLE geospatial_table (id INT, g GEOGRAPHY)")
         self.validate_identity("CREATE MATERIALIZED VIEW a COMMENT='...' AS SELECT 1 FROM x")
         self.validate_identity("CREATE DATABASE mytestdb_clone CLONE mytestdb")
         self.validate_identity("CREATE SCHEMA mytestschema_clone CLONE testschema")
Repository: tobymao/sqlglot

Issue:
SparkSQL negative intervals are being generated incorrectly
```
>>> x = sqlglot.parse_one("INTERVAL -86 days", read="spark")
>>> x.sql(dialect="spark")
'INTERVAL (-86) days'
```

SparkSQL fails on `INTERVAL (-86) days` but will accept `INTERVAL '-86' days` or `INTERVAL -86 days`.


Discussion:

Resolving patch:
diff --git a/sqlglot/generator.py b/sqlglot/generator.py
--- a/sqlglot/generator.py
+++ b/sqlglot/generator.py
@@ -232,7 +232,7 @@ class Generator:
 
     RESERVED_KEYWORDS: t.Set[str] = set()
     WITH_SEPARATED_COMMENTS = (exp.Select, exp.From, exp.Where, exp.With)
-    UNWRAPPED_INTERVAL_VALUES = (exp.Literal, exp.Paren, exp.Column)
+    UNWRAPPED_INTERVAL_VALUES = (exp.Column, exp.Literal, exp.Neg, exp.Paren)
 
     SENTINEL_LINE_BREAK = "__SQLGLOT__LB__"
 


Test patch:
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
@@ -214,6 +214,7 @@ def test_hint(self):
         )
 
     def test_spark(self):
+        self.validate_identity("INTERVAL -86 days")
         self.validate_identity("SELECT UNIX_TIMESTAMP()")
         self.validate_identity("TRIM('    SparkSQL   ')")
         self.validate_identity("TRIM(BOTH 'SL' FROM 'SSparkSQLS')")
Repository: tobymao/sqlglot

Issue:
`initcap` accepts 2 arguments on Snowflake
Hi! SQLGlot currently raises an error when `initcap` is called with a second argument which is allowed on Snowflake.

**Fully reproducible code snippet**

```
import sqlglot
sqlglot.transpile("select initcap('this is a-test', ' ')", read="snowflake")
```

SQLGlot Error:
```
sqlglot.errors.ParseError: The number of provided arguments (2) is greater than the maximum number of supported arguments (1). Line 1, Col: 38.
  select initcap('this is a-test', ' ')
```

**Official Documentation**
https://docs.snowflake.com/en/sql-reference/functions/initcap



Discussion:

Resolving patch:
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -3931,7 +3931,7 @@ class IfNull(Func):
 
 
 class Initcap(Func):
-    pass
+    arg_types = {"this": True, "expression": False}
 
 
 class JSONKeyValue(Expression):


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
@@ -6,6 +6,7 @@ class TestSnowflake(Validator):
     dialect = "snowflake"
 
     def test_snowflake(self):
+        self.validate_identity("INITCAP('iqamqinterestedqinqthisqtopic', 'q')")
         self.validate_identity("CAST(x AS GEOMETRY)")
         self.validate_identity("OBJECT_CONSTRUCT(*)")
         self.validate_identity("SELECT TO_DATE('2019-02-28') + INTERVAL '1 day, 1 year'")
Repository: tobymao/sqlglot

Issue:
Parsing fails when selecting from a column called `desc` on Snowflake
Hi, I found a parsing issue when we read from a column called `desc` in Snowflake.

**Fully reproducible code snippet**
```
import sqlglot

my_sql  = """
with my_cte as (
    select 'a' as desc
)

select 
    desc as description 
from my_cte
"""

sqlglot.transpile(my_sql, read="snowflake")
```

raises:
```
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 7, Col: 8.
```

The code runs correctly in Snowflake though.



Discussion:

Resolving patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -206,6 +206,7 @@ class Parser(metaclass=_Parser):
         TokenType.VAR,
         TokenType.ANTI,
         TokenType.APPLY,
+        TokenType.ASC,
         TokenType.AUTO_INCREMENT,
         TokenType.BEGIN,
         TokenType.BOTH,
@@ -220,6 +221,7 @@ class Parser(metaclass=_Parser):
         TokenType.CONSTRAINT,
         TokenType.DEFAULT,
         TokenType.DELETE,
+        TokenType.DESC,
         TokenType.DESCRIBE,
         TokenType.DIV,
         TokenType.END,


Test patch:
diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql
--- a/tests/fixtures/identity.sql
+++ b/tests/fixtures/identity.sql
@@ -822,3 +822,5 @@ SELECT NEXT VALUE FOR db.schema.sequence_name OVER (ORDER BY foo), col
 SELECT PERCENTILE_CONT(x, 0.5) OVER ()
 SELECT PERCENTILE_CONT(x, 0.5 RESPECT NULLS) OVER ()
 SELECT PERCENTILE_CONT(x, 0.5 IGNORE NULLS) OVER ()
+WITH my_cte AS (SELECT 'a' AS desc) SELECT desc AS description FROM my_cte
+WITH my_cte AS (SELECT 'a' AS asc) SELECT asc AS description FROM my_cte
Repository: tobymao/sqlglot

Issue:
bigquery create table as select with limit

Calling `sqlglot.parse_one(sql, read='bigquery')` fails on this SQL, seemingly because the limit clause gets associated with the create table instead of the select.

```sql
CREATE TABLE IF NOT EXISTS CENSUS.my_table_name AS SELECT `col1`, `col2` FROM CENSUS.my_base_table
  EXCEPT DISTINCT (
    SELECT `col1`, `col2` FROM CENSUS.my_third_table
  )
 LIMIT 0;
```

I'm not sure why you'd write this sort of query with the except distinct clause, but Census seems to generate this SQL.


Discussion:

Resolving patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -4135,8 +4135,8 @@ def _parse_select_or_expression(self, alias: bool = False) -> t.Optional[exp.Exp
         )
 
     def _parse_ddl_select(self) -> t.Optional[exp.Expression]:
-        return self._parse_set_operations(
-            self._parse_select(nested=True, parse_subquery_alias=False)
+        return self._parse_query_modifiers(
+            self._parse_set_operations(self._parse_select(nested=True, parse_subquery_alias=False))
         )
 
     def _parse_transaction(self) -> exp.Expression:


Test patch:
diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py
--- a/tests/dialects/test_bigquery.py
+++ b/tests/dialects/test_bigquery.py
@@ -31,6 +31,9 @@ def test_bigquery(self):
         self.validate_identity(
             "SELECT * FROM (SELECT * FROM `t`) AS a UNPIVOT((c) FOR c_name IN (v1, v2))"
         )
+        self.validate_identity(
+            "CREATE TABLE IF NOT EXISTS foo AS SELECT * FROM bla EXCEPT DISTINCT (SELECT * FROM bar) LIMIT 0"
+        )
 
         self.validate_all('x <> ""', write={"bigquery": "x <> ''"})
         self.validate_all('x <> """"""', write={"bigquery": "x <> ''"})
Repository: tobymao/sqlglot

Issue:
DATE_SUB from BigQuery produces DuckDB code giving number of intervals, rather than subtracted date
```
>>> sqlglot.transpile("SELECT DATE_SUB(date_in_table, INTERVAL 5 DAY) AS five_days_ago from table;", read="bigquery", write="duckdb")
['SELECT DATE_SUB(date_in_table, 5, DAY) AS five_days_ago FROM table']
>>> sqlglot.transpile("SELECT DATE_ADD(date_in_table, INTERVAL 5 DAY) AS five_days_from_now from table;", read="bigquery", write="duckdb")
['SELECT date_in_table + INTERVAL 5 DAY AS five_days_from_now FROM table']
```

BigQuery uses DATE_SUB with INTERVAL to subtract dates, whereas DuckDb uses the `-` operator with INTERVAL.
As you can see conversion from BigQuery DATE_ADD works as expected.

**Official Documentation**
* https://duckdb.org/docs/sql/functions/date.html
* https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_sub



Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py
--- a/sqlglot/dialects/duckdb.py
+++ b/sqlglot/dialects/duckdb.py
@@ -31,10 +31,11 @@ def _ts_or_ds_add_sql(self: generator.Generator, expression: exp.TsOrDsAdd) -> s
     return f"CAST({this} AS DATE) + {self.sql(exp.Interval(this=expression.expression, unit=unit))}"
 
 
-def _date_add_sql(self: generator.Generator, expression: exp.DateAdd) -> str:
+def _date_delta_sql(self: generator.Generator, expression: exp.DateAdd | exp.DateSub) -> str:
     this = self.sql(expression, "this")
     unit = self.sql(expression, "unit").strip("'") or "DAY"
-    return f"{this} + {self.sql(exp.Interval(this=expression.expression, unit=unit))}"
+    op = "+" if isinstance(expression, exp.DateAdd) else "-"
+    return f"{this} {op} {self.sql(exp.Interval(this=expression.expression, unit=unit))}"
 
 
 def _array_sort_sql(self: generator.Generator, expression: exp.ArraySort) -> str:
@@ -183,7 +184,8 @@ class Generator(generator.Generator):
             exp.DayOfWeek: rename_func("DAYOFWEEK"),
             exp.DayOfYear: rename_func("DAYOFYEAR"),
             exp.DataType: _datatype_sql,
-            exp.DateAdd: _date_add_sql,
+            exp.DateAdd: _date_delta_sql,
+            exp.DateSub: _date_delta_sql,
             exp.DateDiff: lambda self, e: self.func(
                 "DATE_DIFF", f"'{e.args.get('unit', 'day')}'", e.expression, e.this
             ),


Test patch:
diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py
--- a/tests/dialects/test_duckdb.py
+++ b/tests/dialects/test_duckdb.py
@@ -379,6 +379,14 @@ def test_duckdb(self):
                 "hive": "SELECT DATE_ADD(TO_DATE(x), 1)",
             },
         )
+        self.validate_all(
+            "SELECT CAST('2020-05-06' AS DATE) - INTERVAL 5 DAY",
+            read={"bigquery": "SELECT DATE_SUB(CAST('2020-05-06' AS DATE), INTERVAL 5 DAY)"},
+        )
+        self.validate_all(
+            "SELECT CAST('2020-05-06' AS DATE) + INTERVAL 5 DAY",
+            read={"bigquery": "SELECT DATE_ADD(CAST('2020-05-06' AS DATE), INTERVAL 5 DAY)"},
+        )
 
         with self.assertRaises(UnsupportedError):
             transpile(
Repository: tobymao/sqlglot

Issue:
Cannot convert Redshift STRTOL to Trino
```
sql = """SELECT STRTOL('abc', 16)"""
converted_sql = sqlglot.transpile(sql, read="redshift", write="trino")[0]
print(converted_sql)
SELECT STRTOL('abc', 16)
```

Trino error: `Function 'strtol' not registered`

a fix could be replace STRTOL with FROM_BASE


Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/redshift.py b/sqlglot/dialects/redshift.py
--- a/sqlglot/dialects/redshift.py
+++ b/sqlglot/dialects/redshift.py
@@ -3,6 +3,7 @@
 import typing as t
 
 from sqlglot import exp, transforms
+from sqlglot.dialects.dialect import rename_func
 from sqlglot.dialects.postgres import Postgres
 from sqlglot.helper import seq_get
 from sqlglot.tokens import TokenType
@@ -34,6 +35,7 @@ class Parser(Postgres.Parser):
                 unit=seq_get(args, 0),
             ),
             "NVL": exp.Coalesce.from_arg_list,
+            "STRTOL": exp.FromBase.from_arg_list,
         }
 
         CONVERT_TYPE_FIRST = True
@@ -105,6 +107,7 @@ class Generator(Postgres.Generator):
             exp.JSONExtractScalar: _json_sql,
             exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
             exp.SortKeyProperty: lambda self, e: f"{'COMPOUND ' if e.args['compound'] else ''}SORTKEY({self.format_args(*e.this)})",
+            exp.FromBase: rename_func("STRTOL"),
         }
 
         # Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots
diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -4392,6 +4392,10 @@ class NumberToStr(Func):
     arg_types = {"this": True, "format": True}
 
 
+class FromBase(Func):
+    arg_types = {"this": True, "expression": True}
+
+
 class Struct(Func):
     arg_types = {"expressions": True}
     is_var_len_args = True


Test patch:
diff --git a/tests/dialects/test_redshift.py b/tests/dialects/test_redshift.py
--- a/tests/dialects/test_redshift.py
+++ b/tests/dialects/test_redshift.py
@@ -10,6 +10,16 @@ def test_redshift(self):
         self.validate_identity("foo$")
         self.validate_identity("$foo")
 
+        self.validate_all(
+            "SELECT STRTOL('abc', 16)",
+            read={
+                "trino": "SELECT FROM_BASE('abc', 16)",
+            },
+            write={
+                "redshift": "SELECT STRTOL('abc', 16)",
+                "trino": "SELECT FROM_BASE('abc', 16)",
+            },
+        )
         self.validate_all(
             "SELECT SNAPSHOT, type",
             write={
Repository: tobymao/sqlglot

Issue:
Support Postgres UNNEST
Postgres' [`unnest`](https://www.postgresql.org/docs/15/functions-array.html) does the same as e.g. Spark's [`explode`](https://spark.apache.org/docs/3.1.3/api/python/reference/api/pyspark.sql.functions.explode.html). `exp.Unnest` exists and is tokenized, but for Postgres it's parsed as an anonymous function:

```
>>> sqlglot.__version__
'16.0.0'
>>> sqlglot.parse_one("select unnest(c) from t", read='postgres')
(SELECT expressions:
  (ANONYMOUS this: unnest, expressions:
    (COLUMN this:
      (IDENTIFIER this: c, quoted: False))), from:
  (FROM this:
    (TABLE this:
      (IDENTIFIER this: t, quoted: False))))
>>> sqlglot.parse_one("select unnest(array[1])", read='postgres')
(SELECT expressions:
  (ANONYMOUS this: unnest, expressions:
    (ARRAY expressions:
      (LITERAL this: 1, is_string: False))))
```

On transpile to Presto (which is the behaviour I want), its behaviour should be the same as for `exp.Explode`.


Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py
--- a/sqlglot/dialects/postgres.py
+++ b/sqlglot/dialects/postgres.py
@@ -269,6 +269,7 @@ class Parser(parser.Parser):
             "NOW": exp.CurrentTimestamp.from_arg_list,
             "TO_CHAR": format_time_lambda(exp.TimeToStr, "postgres"),
             "TO_TIMESTAMP": _to_timestamp,
+            "UNNEST": exp.Explode.from_arg_list,
         }
 
         FUNCTION_PARSERS = {
@@ -329,6 +330,7 @@ class Generator(generator.Generator):
             **generator.Generator.TRANSFORMS,
             exp.BitwiseXor: lambda self, e: self.binary(e, "#"),
             exp.ColumnDef: transforms.preprocess([_auto_increment_to_serial, _serial_to_generated]),
+            exp.Explode: rename_func("UNNEST"),
             exp.JSONExtract: arrow_json_extract_sql,
             exp.JSONExtractScalar: arrow_json_extract_scalar_sql,
             exp.JSONBExtract: lambda self, e: self.binary(e, "#>"),


Test patch:
diff --git a/tests/dialects/test_postgres.py b/tests/dialects/test_postgres.py
--- a/tests/dialects/test_postgres.py
+++ b/tests/dialects/test_postgres.py
@@ -85,6 +85,28 @@ def test_ddl(self):
                 read="postgres",
             )
 
+    def test_unnest(self):
+        self.validate_identity(
+            "SELECT * FROM UNNEST(ARRAY[1, 2], ARRAY['foo', 'bar', 'baz']) AS x(a, b)"
+        )
+
+        self.validate_all(
+            "SELECT UNNEST(c) FROM t",
+            write={
+                "hive": "SELECT EXPLODE(c) FROM t",
+                "postgres": "SELECT UNNEST(c) FROM t",
+                "presto": "SELECT col FROM t CROSS JOIN UNNEST(c) AS _u(col)",
+            },
+        )
+        self.validate_all(
+            "SELECT UNNEST(ARRAY[1])",
+            write={
+                "hive": "SELECT EXPLODE(ARRAY(1))",
+                "postgres": "SELECT UNNEST(ARRAY[1])",
+                "presto": "SELECT col FROM UNNEST(ARRAY[1]) AS _u(col)",
+            },
+        )
+
     def test_postgres(self):
         self.validate_identity("CAST(x AS INT4RANGE)")
         self.validate_identity("CAST(x AS INT4MULTIRANGE)")
Repository: tobymao/sqlglot

Issue:
Postgres array indexes are incorrectly incremented when transpiling to Presto
Both Postgres and Trino are 1-indexed, but SQLGlot adds a 1.

```
>>> sqlglot.__version__
'16.1.3'
>>> sqlglot.transpile("select col[1]", read='postgres', write='presto')[0]
Applying array index offset (1)
'SELECT col[2]'
```

So Postgres should have an `INDEX_OFFSET = 1`, like Presto
https://github.com/tobymao/sqlglot/blob/3b95a465311e969eb8348d57dc9a9acc623a92ab/sqlglot/dialects/presto.py#L178


Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py
--- a/sqlglot/dialects/postgres.py
+++ b/sqlglot/dialects/postgres.py
@@ -183,6 +183,7 @@ def _to_timestamp(args: t.List) -> exp.Expression:
 
 
 class Postgres(Dialect):
+    INDEX_OFFSET = 1
     NULL_ORDERING = "nulls_are_large"
     TIME_FORMAT = "'YYYY-MM-DD HH24:MI:SS'"
     TIME_MAPPING = {


Test patch:
diff --git a/tests/dialects/test_postgres.py b/tests/dialects/test_postgres.py
--- a/tests/dialects/test_postgres.py
+++ b/tests/dialects/test_postgres.py
@@ -107,6 +107,16 @@ def test_unnest(self):
             },
         )
 
+    def test_array_offset(self):
+        self.validate_all(
+            "SELECT col[1]",
+            write={
+                "hive": "SELECT col[0]",
+                "postgres": "SELECT col[1]",
+                "presto": "SELECT col[1]",
+            },
+        )
+
     def test_postgres(self):
         self.validate_identity("CAST(x AS INT4RANGE)")
         self.validate_identity("CAST(x AS INT4MULTIRANGE)")
Repository: tobymao/sqlglot

Issue:
Teradata: TOP N is not supported
Thankyou for SQLGLOT. Fantastic library.

The below fails 
```python
import sqlglot

sqlglot.transpile("select top 10 column1 from table1.column1", identity=True, read="teradata")
```

***Error***
```
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 1, Col: 12.
  select top 10 column1 from table1.column1
```

**Official Documentation**
[Teradata SQL reference](https://docs.teradata.com/r/2_MC9vCtAJRlKle2Rpb0mA/__1TX6kDYjUS0vA5Hi0Y0g)

I will be happy to contribute the fix but I am new here and would like some guidance on where to start. If my guess is right, I will have to make changes only to the `KEYWORDS` dict in `dialects/teradata.py` to add `"TOP": TokenType.TOP` but I am not entirely sure. I will watch and learn for the next time. 

Thanks again for this library. 



Discussion:

Resolving patch:
diff --git a/sqlglot/dialects/teradata.py b/sqlglot/dialects/teradata.py
--- a/sqlglot/dialects/teradata.py
+++ b/sqlglot/dialects/teradata.py
@@ -31,18 +31,19 @@ class Tokenizer(tokens.Tokenizer):
         # https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Comparison-Operators-and-Functions/Comparison-Operators/ANSI-Compliance
         KEYWORDS = {
             **tokens.Tokenizer.KEYWORDS,
+            "^=": TokenType.NEQ,
             "BYTEINT": TokenType.SMALLINT,
-            "SEL": TokenType.SELECT,
+            "GE": TokenType.GTE,
+            "GT": TokenType.GT,
             "INS": TokenType.INSERT,
-            "MOD": TokenType.MOD,
-            "LT": TokenType.LT,
             "LE": TokenType.LTE,
-            "GT": TokenType.GT,
-            "GE": TokenType.GTE,
-            "^=": TokenType.NEQ,
+            "LT": TokenType.LT,
+            "MOD": TokenType.MOD,
             "NE": TokenType.NEQ,
             "NOT=": TokenType.NEQ,
+            "SEL": TokenType.SELECT,
             "ST_GEOMETRY": TokenType.GEOMETRY,
+            "TOP": TokenType.TOP,
         }
 
         # Teradata does not support % as a modulo operator


Test patch:
diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py
--- a/tests/dialects/test_dialect.py
+++ b/tests/dialects/test_dialect.py
@@ -1300,6 +1300,7 @@ def test_limit(self):
         self.validate_all(
             "SELECT x FROM y LIMIT 10",
             read={
+                "teradata": "SELECT TOP 10 x FROM y",
                 "tsql": "SELECT TOP 10 x FROM y",
             },
             write={
Repository: tobymao/sqlglot

Issue:
Snowflake: TOP <n> is not supported
Copying recent issue #1798, Snowflake supports the same Teradata syntax for [Top N](https://docs.snowflake.com/en/sql-reference/constructs/top_n).

The below fails in sqlglot
```
import sqlglot

sqlglot.transpile("select top 10 column1 from table1.column1", identity=True, read="snowflake")

ParseError: Invalid expression / Unexpected token. Line 1, Col: 13.
  select top 10 column1 from table1.column1
```

Solution is the same applied in #1799 (add TOP in supported keywords list in snowflake dialect). 

Thank you for this library!



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
@@ -285,11 +285,12 @@ class Tokenizer(tokens.Tokenizer):
             "NCHAR VARYING": TokenType.VARCHAR,
             "PUT": TokenType.COMMAND,
             "RENAME": TokenType.REPLACE,
+            "SAMPLE": TokenType.TABLE_SAMPLE,
             "TIMESTAMP_LTZ": TokenType.TIMESTAMPLTZ,
             "TIMESTAMP_NTZ": TokenType.TIMESTAMP,
             "TIMESTAMP_TZ": TokenType.TIMESTAMPTZ,
             "TIMESTAMPNTZ": TokenType.TIMESTAMP,
-            "SAMPLE": TokenType.TABLE_SAMPLE,
+            "TOP": TokenType.TOP,
         }
 
         SINGLE_TOKENS = {


Test patch:
diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py
--- a/tests/dialects/test_dialect.py
+++ b/tests/dialects/test_dialect.py
@@ -1302,6 +1302,7 @@ def test_limit(self):
             read={
                 "teradata": "SELECT TOP 10 x FROM y",
                 "tsql": "SELECT TOP 10 x FROM y",
+                "snowflake": "SELECT TOP 10 x FROM y",
             },
             write={
                 "sqlite": "SELECT x FROM y LIMIT 10",