dyyyyyyyy/swe-rebench-filtered-1150 huggingface dataset:
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index c1d86954..14c5e964 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -578,7 +578,7 @@ class Parser(metaclass=_Parser):
         TokenType.PLACEHOLDER: lambda self: self.expression(exp.Placeholder),
         TokenType.PARAMETER: lambda self: self._parse_parameter(),
         TokenType.COLON: lambda self: self.expression(exp.Placeholder, this=self._prev.text)
-        if self._match_set((TokenType.NUMBER, TokenType.VAR))
+        if self._match(TokenType.NUMBER) or self._match_set(self.ID_VAR_TOKENS)
         else None,
     }
 

problem_statement: Unable to parse the oracle query when ":OBJECT" bind is present
Hello,

Parser is throwing an error when there is ":OBJECT" bind is present in the oracle query.

**Code for your reference -**

```
import sqlglot.expressions as exp

query ="""
SELECT A.COL1, B.COL2 FROM SCHEMA1.TABLE1 A, SCHEMA2.TABLE2 B WHERE A.COL1 = :OBJECT AND B.COL2 = :SOMEVARIABLE 
"""

expressions = sqlglot.parse_one(query, read='oracle')
x = list(expressions.find_all(exp.Table))

for i in x:
  listTables = str(i).split(' ')[0]
  print(listTables)
```


Above code works fine if Bind name is different that OBJECT. If ':OBJECT' is present in the query, then it fails.

Request you to add support for ':OBJECT' for query parsing.
Unable to parse the oracle query when "#" is present in the column names
Hello,

Parser is throwing an error when there is "#" character is present in the column name.

**Code for your reference -**

```
import sqlglot.expressions as exp

query ="""
SELECT A.COL#, B.COL2 FROM SCHEMA1.TABLE1 A
"""

expressions = sqlglot.parse_one(query, read='oracle')
x = list(expressions.find_all(exp.Table))

for i in x:
  listTables = str(i).split(' ')[0]
  print(listTables)
```


Above code fails as it cannot process '#' and throws the error.
Request you to add support for '#' for query parsing.
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_oracle.py b/tests/dialects/test_oracle.py
index 694cd68b..fb8f8fbb 100644
--- a/tests/dialects/test_oracle.py
+++ b/tests/dialects/test_oracle.py
@@ -6,6 +6,7 @@ class TestOracle(Validator):
     dialect = "oracle"
 
     def test_oracle(self):
+        self.validate_identity("SELECT :OBJECT")
         self.validate_identity("SELECT * FROM t FOR UPDATE")
         self.validate_identity("SELECT * FROM t FOR UPDATE WAIT 5")
         self.validate_identity("SELECT * FROM t FOR UPDATE NOWAIT")
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index 67b41110..7df8be23 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -4174,6 +4174,10 @@ class Abs(Func):
     pass
 
 
+class ApproxTopK(AggFunc):
+    arg_types = {"this": True, "expression": False, "counters": False}
+
+
 class Flatten(Func):
     pass
 

problem_statement: approx_top_k is not recognized as an aggregation function in Snowflake
**Fully reproducible code snippet**

```python
from sqlglot import Dialects, exp, parse_one

query = "SELECT approx_top_k(field, 5) FROM  some_table"
parsed_query = parse_one(query, read=Dialects.SNOWFLAKE.value)
agg_funcs = parsed_query.find_all(exp.AggFunc)
has_agg_funcs = any(agg_funcs) # getting False, expected True

```

**Official Documentation**
https://docs.snowflake.com/en/sql-reference/functions/approx_top_k

repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index 78dfabe5..65b77ea0 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -9,6 +9,10 @@ class TestSnowflake(Validator):
     dialect = "snowflake"
 
     def test_snowflake(self):
+        expr = parse_one("SELECT APPROX_TOP_K(C4, 3, 5) FROM t")
+        expr.selects[0].assert_is(exp.AggFunc)
+        self.assertEqual(expr.sql(dialect="snowflake"), "SELECT APPROX_TOP_K(C4, 3, 5) FROM t")
+
         self.validate_identity("SELECT DAYOFMONTH(CURRENT_TIMESTAMP())")
         self.validate_identity("SELECT DAYOFYEAR(CURRENT_TIMESTAMP())")
         self.validate_identity("LISTAGG(data['some_field'], ',')")
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
index 01f7512a..62b1cd0c 100644
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -349,7 +349,7 @@ class Snowflake(Dialect):
             table: t.Optional[exp.Expression] = None
             if self._match_text_seq("@"):
                 table_name = "@"
-                while True:
+                while self._curr:
                     self._advance()
                     table_name += self._prev.text
                     if not self._match_set(self.STAGED_FILE_SINGLE_TOKENS, advance=False):

problem_statement: List index out of range for Snowflake SQL transpilation
Ran the issue using the latest `main` build `sqlglot-19.0.4.dev18`

Read: `snowflake`
Write `spark` 

When running the following query on Snowflake's publically available documentation, we get an `IndexError: list index out of range`. It's unclear which part of the query is unable to be tokenized. 

Code snippet 

https://docs.snowflake.com/en/sql-reference/sql/create-external-table

```
query_1666 = 'SELECT metadata$filename FROM @s1/;'

transpiled_sqls = transpile(query_1666, read='snowflake', write='spark', pretty=True, error_level=None)
```

repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index ede42f47..7452a8c9 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -552,6 +552,7 @@ class TestSnowflake(Validator):
             staged_file.sql(dialect="snowflake"),
         )
 
+        self.validate_identity("SELECT metadata$filename FROM @s1/")
         self.validate_identity("SELECT * FROM @~")
         self.validate_identity("SELECT * FROM @~/some/path/to/file.csv")
         self.validate_identity("SELECT * FROM @mystage")
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/tokens.py b/sqlglot/tokens.py
index ef431119..ef3dc237 100644
--- a/sqlglot/tokens.py
+++ b/sqlglot/tokens.py
@@ -587,6 +587,7 @@ class Tokenizer(metaclass=_Tokenizer):
             # Ensures we don't count an extra line if we get a \r\n line break sequence
             if self._char == "\r" and self._peek == "\n":
                 i = 2
+                self._start += 1
 
             self._col = 1
             self._line += 1
diff --git a/sqlglotrs/src/tokenizer.rs b/sqlglotrs/src/tokenizer.rs
index eb800f09..f386ce63 100644
--- a/sqlglotrs/src/tokenizer.rs
+++ b/sqlglotrs/src/tokenizer.rs
@@ -140,6 +140,7 @@ impl<'a> TokenizerState<'a> {
             // Ensures we don't count an extra line if we get a \r\n line break sequence.
             if self.current_char == '\r' && self.peek_char == '\n' {
                 i = 2;
+                self.start += 1;
             }
 
             self.column = 1;

problem_statement: \r\n sometimes causes a parsing error
Repro

```python
from sqlglot import parse_one
parse_one('select a\r\nfrom b')
``` 

It appears that when the fix went in for line numbers, that the advance function skips the \n, but doesn't advance start, so the text becomes \nfrom which doesn't match.
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/test_tokens.py b/tests/test_tokens.py
index b97f54a6..970c1ac2 100644
--- a/tests/test_tokens.py
+++ b/tests/test_tokens.py
@@ -71,6 +71,20 @@ x"""
         self.assertEqual(tokens[2].line, 2)
         self.assertEqual(tokens[3].line, 3)
 
+    def test_crlf(self):
+        tokens = Tokenizer().tokenize("SELECT a\r\nFROM b")
+        tokens = [(token.token_type, token.text) for token in tokens]
+
+        self.assertEqual(
+            tokens,
+            [
+                (TokenType.SELECT, "SELECT"),
+                (TokenType.VAR, "a"),
+                (TokenType.FROM, "FROM"),
+                (TokenType.VAR, "b"),
+            ],
+        )
+
     def test_command(self):
         tokens = Tokenizer().tokenize("SHOW;")
         self.assertEqual(tokens[0].token_type, TokenType.SHOW)
diff --git a/tests/test_transpile.py b/tests/test_transpile.py
index b732b459..fb8f8313 100644
--- a/tests/test_transpile.py
+++ b/tests/test_transpile.py
@@ -89,6 +89,7 @@ class TestTranspile(unittest.TestCase):
         self.validate("SELECT MIN(3)>=MIN(2)", "SELECT MIN(3) >= MIN(2)")
         self.validate("SELECT 1>0", "SELECT 1 > 0")
         self.validate("SELECT 3>=3", "SELECT 3 >= 3")
+        self.validate("SELECT a\r\nFROM b", "SELECT a FROM b")
 
     def test_comments(self):
         self.validate(
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
index ad14e6ee..454df94c 100644
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -328,6 +328,9 @@ def _parse_colon_get_path(
         if not self._match(TokenType.COLON):
             break
 
+    if self._match_set(self.RANGE_PARSERS):
+        this = self.RANGE_PARSERS[self._prev.token_type](self, this) or this
+
     return this
 
 

problem_statement: ParseError when using LIKE/ILIKE on an element in an object in Snowflake
I'm getting `ParseError: Invalid expression / Unexpected token` when using `LIKE` or `ILIKE` on an element within an object in Snowflake.

Example:
```
import sqlglot
sqlglot.parse(""" select parse_json('{"x": "hello"}'):x like 'hello' """, read="snowflake")
sqlglot.parse(""" select data:x like 'hello' from some_table """, read="snowflake")
```

Both of these cause the parsing error, but both are valid Snowflake statements.
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index 602bc630..39963b28 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -78,6 +78,14 @@ WHERE
         self.validate_identity(
             "SELECT a FROM test PIVOT(SUM(x) FOR y IN ('z', 'q')) AS x TABLESAMPLE (0.1)"
         )
+        self.validate_identity(
+            """SELECT PARSE_JSON('{"x": "hello"}'):x LIKE 'hello'""",
+            """SELECT GET_PATH(PARSE_JSON('{"x": "hello"}'), 'x') LIKE 'hello'""",
+        )
+        self.validate_identity(
+            """SELECT data:x LIKE 'hello' FROM some_table""",
+            """SELECT GET_PATH(data, 'x') LIKE 'hello' FROM some_table""",
+        )
         self.validate_identity(
             "SELECT SUM({ fn CONVERT(123, SQL_DOUBLE) })",
             "SELECT SUM(CAST(123 AS DOUBLE))",
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/dialects/snowflake.py b/sqlglot/dialects/snowflake.py
index f88f3eb1..6ca8e9de 100644
--- a/sqlglot/dialects/snowflake.py
+++ b/sqlglot/dialects/snowflake.py
@@ -663,7 +663,9 @@ class Snowflake(Dialect):
             "MINUS": TokenType.EXCEPT,
             "NCHAR VARYING": TokenType.VARCHAR,
             "PUT": TokenType.COMMAND,
+            "REMOVE": TokenType.COMMAND,
             "RENAME": TokenType.REPLACE,
+            "RM": TokenType.COMMAND,
             "SAMPLE": TokenType.TABLE_SAMPLE,
             "SQL_DOUBLE": TokenType.DOUBLE,
             "SQL_VARCHAR": TokenType.VARCHAR,

problem_statement: sqlglot 20.8.0 incorrectly transpiles or fails to parse Snowflake REMOVE / RM syntax
Snowflake RM / REMOVE syntax is incorrectly transpiled or causes errors for the cases from the documentation: `"RM @parquet_stage;" -> "RM AS $parquet_stage;"` is rejected by Snowflake at runtime, the other cases cause ParseErrors.

## reference
https://docs.snowflake.com/en/sql-reference/sql/remove

## code
```
examples = [
    "RM @parquet_stage;",
    "REMOVE @parquet_stage;",
    "RM @%mytable/myobject;",
    "RM @%mytable/myobject/;",
    "RM @~ pattern='.*jun.*';",
    "REMOVE @%orders;",
    "REMOVE @mystage/path1/subpath2;",
]

import sqlglot
import sqlglot.errors

print(sqlglot.__version__)
for i, s in enumerate(examples):
    try:
        t = sqlglot.transpile(
            s.strip(), read="snowflake", write="snowflake", pretty=True
        )
        print(i, s, "->", t)
    except sqlglot.errors.ParseError as e:
        print(i, "error", e)
```
## output
```
20.8.0
0 RM @parquet_stage; -> ['RM AS $parquet_stage']
1 REMOVE @parquet_stage; -> ['REMOVE AS $parquet_stage']
2 error Required keyword: 'this' missing for <class 'sqlglot.expressions.Parameter'>. Line 1, Col: 5.
  RM @%mytable/myobject;
3 error Required keyword: 'this' missing for <class 'sqlglot.expressions.Parameter'>. Line 1, Col: 5.
  RM @%mytable/myobject/;
4 error Required keyword: 'this' missing for <class 'sqlglot.expressions.Parameter'>. Line 1, Col: 5.
  RM @~ pattern='.*jun.*';
5 error Required keyword: 'this' missing for <class 'sqlglot.expressions.Parameter'>. Line 1, Col: 9.
  REMOVE @%orders;
6 error Invalid expression / Unexpected token. Line 1, Col: 16.
  REMOVE @mystage/path1/subpath2;
```
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index 1f365bea..5dd81cdc 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -39,6 +39,8 @@ WHERE
   )""",
         )
 
+        self.validate_identity("RM @parquet_stage")
+        self.validate_identity("REMOVE @parquet_stage")
         self.validate_identity("SELECT TIMESTAMP_FROM_PARTS(d, t)")
         self.validate_identity("SELECT GET_PATH(v, 'attr[0].name') FROM vartab")
         self.validate_identity("SELECT TO_ARRAY(CAST(x AS ARRAY))")
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index b99d34c0..854f5e7d 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -4534,7 +4534,11 @@ class Parser(metaclass=_Parser):
 
         while self._match(TokenType.COLON):
             start_index = self._index
-            path = self._parse_column_ops(self._parse_field(any_token=True))
+
+            # Snowflake allows reserved keywords as json keys but advance_any() excludes TokenType.SELECT from any_tokens=True
+            path = self._parse_column_ops(
+                self._parse_field(any_token=True, tokens=(TokenType.SELECT,))
+            )
 
             # The cast :: operator has a lower precedence than the extraction operator :, so
             # we rearrange the AST appropriately to avoid casting the JSON path

problem_statement: Parsing fails when struct / json field is called `select`
**Fully reproducible code snippet**
```
    query = """
select
    invocations.invocation_args:select::varchar as invocation_select
from table
"""
sqlglot.parse(query, sqlglot.Dialects.SNOWFLAKE)
```

This snippet raises an exception: `sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 3, Col: 19.`

repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index e5bf4f27..12864369 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -125,6 +125,10 @@ WHERE
             "SELECT a:from::STRING, a:from || ' test' ",
             "SELECT CAST(GET_PATH(a, 'from') AS TEXT), GET_PATH(a, 'from') || ' test'",
         )
+        self.validate_identity(
+            "SELECT a:select",
+            "SELECT GET_PATH(a, 'select')",
+        )
         self.validate_identity("x:from", "GET_PATH(x, 'from')")
         self.validate_identity(
             "value:values::string::int",
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 0d2cc2b9..0aae2e40 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -4486,10 +4486,22 @@ class Parser(metaclass=_Parser):
 
     def _parse_struct_types(self, type_required: bool = False) -> t.Optional[exp.Expression]:
         index = self._index
-        this = (
-            self._parse_type(parse_interval=False, fallback_to_identifier=True)
-            or self._parse_id_var()
-        )
+
+        if (
+            self._curr
+            and self._next
+            and self._curr.token_type in self.TYPE_TOKENS
+            and self._next.token_type in self.TYPE_TOKENS
+        ):
+            # Takes care of special cases like `STRUCT<list ARRAY<...>>` where the identifier is also a
+            # type token. Without this, the list will be parsed as a type and we'll eventually crash
+            this = self._parse_id_var()
+        else:
+            this = (
+                self._parse_type(parse_interval=False, fallback_to_identifier=True)
+                or self._parse_id_var()
+            )
+
         self._match(TokenType.COLON)
 
         if (

problem_statement: sqlglot fails to parse BigQuery type cast
**Fully reproducible code snippet**

```python
import sqlglot
sqlglot.parse_one(sql="select sources::STRUCT<list ARRAY<STRUCT<element STRUCT<property STRING, dataset STRING, record_id STRING, confidence FLOAT64>>>> from bar", dialect="bigquery")
```

Produces

```
sqlglot.errors.ParseError: Required keyword: 'expression' missing for <class 'sqlglot.expressions.BitwiseRightShift'>. Line 1, Col: 134
```
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py
index 42cb27f7..a7affe68 100644
--- a/tests/dialects/test_bigquery.py
+++ b/tests/dialects/test_bigquery.py
@@ -103,6 +103,7 @@ LANGUAGE js AS
         select_with_quoted_udf = self.validate_identity("SELECT `p.d.UdF`(data) FROM `p.d.t`")
         self.assertEqual(select_with_quoted_udf.selects[0].name, "p.d.UdF")
 
+        self.validate_identity("CAST(x AS STRUCT<list ARRAY<INT64>>)")
         self.validate_identity("assert.true(1 = 1)")
         self.validate_identity("SELECT ARRAY_TO_STRING(list, '--') AS text")
         self.validate_identity("SELECT jsondoc['some_key']")
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 0aae2e40..2ba64aa2 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -5960,7 +5960,7 @@ class Parser(metaclass=_Parser):
         return None
 
     def _parse_var_or_string(self) -> t.Optional[exp.Expression]:
-        return self._parse_var() or self._parse_string()
+        return self._parse_string() or self._parse_var(any_token=True)
 
     def _parse_primary_or_var(self) -> t.Optional[exp.Expression]:
         return self._parse_primary() or self._parse_var(any_token=True)

problem_statement: parse SQL with CAST FUNCTION exception under MySQL dialect
When I parse the flowing sql using MySQL dialect , it encountered an exception  like 
`’sqlglot.errors.ParseError: Required keyword: 'this' missing for <class 'sqlglot.expressions.CharacterSet'>. Line 1, Col: 61.’`

the SQL is 
`
SELECT CAST(IFNULL(`id`, 'NULL') AS CHAR CHARACTER SET binary) from test`
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_mysql.py b/tests/dialects/test_mysql.py
index 280ebbf2..bfdb2a68 100644
--- a/tests/dialects/test_mysql.py
+++ b/tests/dialects/test_mysql.py
@@ -117,6 +117,7 @@ class TestMySQL(Validator):
         )
 
     def test_identity(self):
+        self.validate_identity("SELECT CAST(COALESCE(`id`, 'NULL') AS CHAR CHARACTER SET binary)")
         self.validate_identity("SELECT e.* FROM e STRAIGHT_JOIN p ON e.x = p.y")
         self.validate_identity("ALTER TABLE test_table ALTER COLUMN test_column SET DEFAULT 1")
         self.validate_identity("SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:00.0000')")
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py
index c25f9f89..cda1c940 100644
--- a/sqlglot/dialects/postgres.py
+++ b/sqlglot/dialects/postgres.py
@@ -365,6 +365,7 @@ class Postgres(Dialect):
             "NOW": exp.CurrentTimestamp.from_arg_list,
             "REGEXP_REPLACE": _build_regexp_replace,
             "TO_CHAR": build_formatted_time(exp.TimeToStr, "postgres"),
+            "TO_DATE": build_formatted_time(exp.StrToDate, "postgres"),
             "TO_TIMESTAMP": _build_to_timestamp,
             "UNNEST": exp.Explode.from_arg_list,
             "SHA256": lambda args: exp.SHA2(this=seq_get(args, 0), length=exp.Literal.number(256)),

problem_statement: Transpile not working for postgres/duckdb
sql = f"""
             SELECT TO_DATE(20220101, 'MM/DD/YYYY') AS order_month
        """ 
        sq = transpile(sql, read="postgres", write="duckdb")

fails to replace to_date, and won't execute on duck
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_postgres.py b/tests/dialects/test_postgres.py
index b89cd940..065f1283 100644
--- a/tests/dialects/test_postgres.py
+++ b/tests/dialects/test_postgres.py
@@ -759,6 +759,14 @@ class TestPostgres(Validator):
             },
         )
 
+        self.validate_all(
+            "SELECT TO_DATE('01/01/2000', 'MM/DD/YYYY')",
+            write={
+                "duckdb": "SELECT CAST(STRPTIME('01/01/2000', '%m/%d/%Y') AS DATE)",
+                "postgres": "SELECT TO_DATE('01/01/2000', 'MM/DD/YYYY')",
+            },
+        )
+
     def test_ddl(self):
         # Checks that user-defined types are parsed into DataType instead of Identifier
         self.parse_one("CREATE TABLE t (a udt)").this.expressions[0].args["kind"].assert_is(
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/dialects/tsql.py b/sqlglot/dialects/tsql.py
index fd3e48cc..9659f153 100644
--- a/sqlglot/dialects/tsql.py
+++ b/sqlglot/dialects/tsql.py
@@ -322,6 +322,15 @@ def _build_with_arg_as_text(
     return _parse
 
 
+def _build_json_query(args: t.List, dialect: Dialect) -> exp.JSONExtract:
+    if len(args) == 1:
+        # The default value for path is '$'. As a result, if you don't provide a
+        # value for path, JSON_QUERY returns the input expression.
+        args.append(exp.Literal.string("$"))
+
+    return parser.build_extract_json_with_path(exp.JSONExtract)(args, dialect)
+
+
 def _json_extract_sql(
     self: TSQL.Generator, expression: exp.JSONExtract | exp.JSONExtractScalar
 ) -> str:
@@ -510,7 +519,7 @@ class TSQL(Dialect):
             "GETDATE": exp.CurrentTimestamp.from_arg_list,
             "HASHBYTES": _build_hashbytes,
             "ISNULL": exp.Coalesce.from_arg_list,
-            "JSON_QUERY": parser.build_extract_json_with_path(exp.JSONExtract),
+            "JSON_QUERY": _build_json_query,
             "JSON_VALUE": parser.build_extract_json_with_path(exp.JSONExtractScalar),
             "LEN": _build_with_arg_as_text(exp.Length),
             "LEFT": _build_with_arg_as_text(exp.Left),

problem_statement: TSQL JSON_QUERY issue
import sqlglot
sqlglot.transpile("""
SELECT
JSON_QUERY(REPLACE(REPLACE(prediction_list , '''', '"'), '""', '"'))
FROM "MyAppDB"."dbo"."predictions_v5"
""", read="tsql", write="tsql")[0]

The query already runs well on my sql server (without transpile), but throws a failure if transpile
ParseError: Required keyword: 'expression' missing for <class 'sqlglot.expressions.JSONExtract'>. Line 3, Col: 68.
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index 9658a02c..a9c29ed3 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -1135,6 +1135,11 @@ WHERE
         self.validate_all("ISNULL(x, y)", write={"spark": "COALESCE(x, y)"})
 
     def test_json(self):
+        self.validate_identity(
+            """JSON_QUERY(REPLACE(REPLACE(x , '''', '"'), '""', '"'))""",
+            """ISNULL(JSON_QUERY(REPLACE(REPLACE(x, '''', '"'), '""', '"'), '$'), JSON_VALUE(REPLACE(REPLACE(x, '''', '"'), '""', '"'), '$'))""",
+        )
+
         self.validate_all(
             "JSON_QUERY(r.JSON, '$.Attr_INT')",
             write={
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/dialects/presto.py b/sqlglot/dialects/presto.py
index c44976be..12469808 100644
--- a/sqlglot/dialects/presto.py
+++ b/sqlglot/dialects/presto.py
@@ -245,13 +245,17 @@ class Presto(Dialect):
     INDEX_OFFSET = 1
     NULL_ORDERING = "nulls_are_last"
     TIME_FORMAT = MySQL.TIME_FORMAT
-    TIME_MAPPING = MySQL.TIME_MAPPING
     STRICT_STRING_CONCAT = True
     SUPPORTS_SEMI_ANTI_JOIN = False
     TYPED_DIVISION = True
     TABLESAMPLE_SIZE_IS_PERCENT = True
     LOG_BASE_FIRST: t.Optional[bool] = None
 
+    TIME_MAPPING = {
+        **MySQL.TIME_MAPPING,
+        "%W": "%A",
+    }
+
     # https://github.com/trinodb/trino/issues/17
     # https://github.com/trinodb/trino/issues/12289
     # https://github.com/prestodb/presto/issues/2863

problem_statement: Incorrect format option for DATE_FORMAT when transpiling from Spark to Presto
The following Spark query:
```
select time, date_format(time, 'EEEE') as weekday
from table
```
is transpiled to this Presto query:
```
SELECT time, DATE_FORMAT(CAST(time AS TIMESTAMP), '%A') AS weekday 
FROM table
```
but the `%A` option should be `%W` ([Presto doc](https://prestodb.io/docs/current/functions/datetime.html)). `%A` is not a valid format and will return `A`.

repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_spark.py b/tests/dialects/test_spark.py
index fc3146f6..9d761e94 100644
--- a/tests/dialects/test_spark.py
+++ b/tests/dialects/test_spark.py
@@ -297,6 +297,13 @@ TBLPROPERTIES (
                 },
             )
 
+        self.validate_all(
+            "SELECT DATE_FORMAT(DATE '2020-01-01', 'EEEE') AS weekday",
+            write={
+                "presto": "SELECT DATE_FORMAT(CAST(CAST('2020-01-01' AS DATE) AS TIMESTAMP), '%W') AS weekday",
+                "spark": "SELECT DATE_FORMAT(CAST(CAST('2020-01-01' AS DATE) AS TIMESTAMP), 'EEEE') AS weekday",
+            },
+        )
         self.validate_all(
             "SELECT TRY_ELEMENT_AT(MAP(1, 'a', 2, 'b'), 2)",
             read={
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index f1681e21..e8a32db0 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -2848,6 +2848,8 @@ class Parser(metaclass=_Parser):
             table = self._match(TokenType.TABLE)
             this = self._parse_select() or self._parse_string() or self._parse_table()
             return self.expression(exp.Summarize, this=this, table=table)
+        elif self._match(TokenType.DESCRIBE):
+            this = self._parse_describe()
         else:
             this = None
 

problem_statement: selecting from `describe t` using duckdb dialect is incorrect
```
In [7]: import sqlglot.expressions as sge, sqlglot as sg

In [8]: sg.__version__
Out[8]: '25.8.0'

In [9]: sg.parse_one('select * from (describe t)', read="duckdb").sql('duckdb')
Out[9]: 'SELECT * FROM (describe AS t)'
```

DuckDB allows selecting from `DESCRIBE t`:

```
❯ duckdb <<< 'create table t as select 1 as a union select 2; describe t; select column_name from (describe t)'
┌─────────────┬─────────────┬─────────┬─────────┬─────────┬─────────┐
│ column_name │ column_type │  null   │   key   │ default │  extra  │
│   varchar   │   varchar   │ varchar │ varchar │ varchar │ varchar │
├─────────────┼─────────────┼─────────┼─────────┼─────────┼─────────┤
│ a           │ INTEGER     │ YES     │         │         │         │
└─────────────┴─────────────┴─────────┴─────────┴─────────┴─────────┘
┌─────────────┐
│ column_name │
│   varchar   │
├─────────────┤
│ a           │
└─────────────┘
```
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py
index 15af0864..6e37a350 100644
--- a/tests/dialects/test_duckdb.py
+++ b/tests/dialects/test_duckdb.py
@@ -819,6 +819,8 @@ class TestDuckDB(Validator):
 
         self.validate_identity("SELECT LENGTH(foo)")
 
+        self.validate_identity("SELECT * FROM (DESCRIBE t)")
+
     def test_array_index(self):
         with self.assertLogs(helper_logger) as cm:
             self.validate_all(
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 2ae75e17..6ee0cb14 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -6851,13 +6851,13 @@ class Parser(metaclass=_Parser):
             self._match(TokenType.THEN)
 
             if self._match(TokenType.INSERT):
-                _this = self._parse_star()
-                if _this:
-                    then: t.Optional[exp.Expression] = self.expression(exp.Insert, this=_this)
+                this = self._parse_star()
+                if this:
+                    then: t.Optional[exp.Expression] = self.expression(exp.Insert, this=this)
                 else:
                     then = self.expression(
                         exp.Insert,
-                        this=self._parse_value(),
+                        this=exp.var("ROW") if self._match_text_seq("ROW") else self._parse_value(),
                         expression=self._match_text_seq("VALUES") and self._parse_value(),
                     )
             elif self._match(TokenType.UPDATE):

problem_statement: BigQuery: `MERGE ... INSERT ROW` not supported
I stumbled upon this issue in sqlmesh, but assume that sqlglot causes it.
In BigQuery, the `MERGE` statement has an alternative `INSERT ROW` syntax which inserts all columns without having to specify each one explicitly. sqlglot seems to not support this yet, as it treats `ROW` as a column name to insert.

Input: `sqlglot.transpile('merge a using b on false when not matched then insert row', read='bigquery', write='bigquery')`
Output: `['MERGE INTO a USING b ON FALSE WHEN NOT MATCHED THEN INSERT (row)']`

Expected output: `['MERGE INTO a USING b ON FALSE WHEN NOT MATCHED THEN INSERT ROW']`

Documentation: https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement
Example: https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#example_8
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py
index c8c21765..b8838962 100644
--- a/tests/dialects/test_bigquery.py
+++ b/tests/dialects/test_bigquery.py
@@ -191,6 +191,9 @@ LANGUAGE js AS
         self.validate_identity("CAST(x AS NVARCHAR)", "CAST(x AS STRING)")
         self.validate_identity("CAST(x AS TIMESTAMPTZ)", "CAST(x AS TIMESTAMP)")
         self.validate_identity("CAST(x AS RECORD)", "CAST(x AS STRUCT)")
+        self.validate_identity(
+            "MERGE INTO dataset.NewArrivals USING (SELECT * FROM UNNEST([('microwave', 10, 'warehouse #1'), ('dryer', 30, 'warehouse #1'), ('oven', 20, 'warehouse #2')])) ON FALSE WHEN NOT MATCHED THEN INSERT ROW WHEN NOT MATCHED BY SOURCE THEN DELETE"
+        )
         self.validate_identity(
             "SELECT * FROM `SOME_PROJECT_ID.SOME_DATASET_ID.INFORMATION_SCHEMA.SOME_VIEW`"
         )
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py
index 95f3c01c..de48a8a4 100644
--- a/sqlglot/expressions.py
+++ b/sqlglot/expressions.py
@@ -4123,6 +4123,7 @@ class DataType(Expression):
         NUMRANGE = auto()
         NVARCHAR = auto()
         OBJECT = auto()
+        RANGE = auto()
         ROWVERSION = auto()
         SERIAL = auto()
         SET = auto()
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 96df5c01..a9fc38e5 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -269,6 +269,7 @@ class Parser(metaclass=_Parser):
         TokenType.LOWCARDINALITY,
         TokenType.MAP,
         TokenType.NULLABLE,
+        TokenType.RANGE,
         *STRUCT_TYPE_TOKENS,
     }
 

problem_statement: Support BigQuery `RANGE` type
**Is your feature request related to a problem? Please describe.**

BigQuery added a [`RANGE`](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#range_type) type which takes a type parameter, one of `DATE`, `DATETIME` or `TIMESTAMP`

**Describe the solution you'd like**

Add support for this new type.

**Describe alternatives you've considered**

N/A

**Additional context**

Would like to use this type in sqlmesh models.

repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py
index 2c6a6076..e2adfeab 100644
--- a/tests/dialects/test_bigquery.py
+++ b/tests/dialects/test_bigquery.py
@@ -1962,3 +1962,26 @@ OPTIONS (
                 "duckdb": "WITH Races AS (SELECT '800M' AS race) SELECT race, participant FROM Races AS r CROSS JOIN (SELECT UNNEST([{'name': 'Rudisha', 'laps': [23.4, 26.3, 26.4, 26.1]}], max_depth => 2)) AS participant",
             },
         )
+
+    def test_range_type(self):
+        for type, value in (
+            ("RANGE<DATE>", "'[2020-01-01, 2020-12-31)'"),
+            ("RANGE<DATE>", "'[UNBOUNDED, 2020-12-31)'"),
+            ("RANGE<DATETIME>", "'[2020-01-01 12:00:00, 2020-12-31 12:00:00)'"),
+            ("RANGE<TIMESTAMP>", "'[2020-10-01 12:00:00+08, 2020-12-31 12:00:00+08)'"),
+        ):
+            with self.subTest(f"Testing BigQuery's RANGE<T> type: {type} {value}"):
+                self.validate_identity(f"SELECT {type} {value}", f"SELECT CAST({value} AS {type})")
+
+                self.assertEqual(self.parse_one(type), exp.DataType.build(type, dialect="bigquery"))
+
+        self.validate_identity(
+            "SELECT RANGE(CAST('2022-12-01' AS DATE), CAST('2022-12-31' AS DATE))"
+        )
+        self.validate_identity("SELECT RANGE(NULL, CAST('2022-12-31' AS DATE))")
+        self.validate_identity(
+            "SELECT RANGE(CAST('2022-10-01 14:53:27' AS DATETIME), CAST('2022-10-01 16:00:00' AS DATETIME))"
+        )
+        self.validate_identity(
+            "SELECT RANGE(CAST('2022-10-01 14:53:27 America/Los_Angeles' AS TIMESTAMP), CAST('2022-10-01 16:00:00 America/Los_Angeles' AS TIMESTAMP))"
+        )
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/tokens.py b/sqlglot/tokens.py
index 29aa5c42..fd084d86 100644
--- a/sqlglot/tokens.py
+++ b/sqlglot/tokens.py
@@ -649,6 +649,7 @@ class Tokenizer(metaclass=_Tokenizer):
         "<->": TokenType.LR_ARROW,
         "&&": TokenType.DAMP,
         "??": TokenType.DQMARK,
+        "~~~": TokenType.GLOB,
         "ALL": TokenType.ALL,
         "ALWAYS": TokenType.ALWAYS,
         "AND": TokenType.AND,

problem_statement: Incorrect Handling of the `~~~` Operator in DuckDB
When testing SQLGlot with DuckDB, I discovered that the `~~~` operator is incorrectly handled. This operator is equivalent to the `GLOB` keyword in DuckDB, but SQLGlot incorrectly translates it.

#### Original Query:

```sql
SELECT ?::VARCHAR ~~~ ?::VARCHAR LIMIT 1
```

#### SQLGlot Output:

```sql
SELECT REGEXP_MATCHES(CAST(? AS TEXT), ~~CAST(? AS TEXT)) LIMIT 1
```

#### Expected Behavior:
SQLGlot should produce either the `~~~` operator or the `GLOB` function, as defined by DuckDB for pattern matching. The correct translation would be:

```sql
SELECT ?::VARCHAR ~~~ ?::VARCHAR LIMIT 1
```

#### Reference:
The `~~~` operator is documented to function the same as `GLOB` in DuckDB:
- [DuckDB Pattern Matching Documentation](https://duckdb.org/docs/sql/functions/pattern_matching.html)


repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py
index 5925789e..c9f4d62a 100644
--- a/tests/dialects/test_duckdb.py
+++ b/tests/dialects/test_duckdb.py
@@ -866,6 +866,7 @@ class TestDuckDB(Validator):
         )
         self.validate_identity("a ^ b", "POWER(a, b)")
         self.validate_identity("a ** b", "POWER(a, b)")
+        self.validate_identity("a ~~~ b", "a GLOB b")
 
     def test_array_index(self):
         with self.assertLogs(helper_logger) as cm:
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index bb612912..e035dc90 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -3056,7 +3056,11 @@ class Parser(metaclass=_Parser):
         elif self._match(TokenType.DESCRIBE):
             this = self._parse_describe()
         elif self._match_text_seq("STREAM"):
-            this = self.expression(exp.Stream, this=self._parse_function())
+            this = self._parse_function()
+            if this:
+                this = self.expression(exp.Stream, this=this)
+            else:
+                self._retreat(self._index - 1)
         else:
             this = None
 

problem_statement: Queries containing CTE as "stream" are causing an error
### Description
I am encountering an issue similar to [issue](https://github.com/tobymao/sqlglot/issues/4029). While the previous PR addressed cases where the string contained the keyword "stream," I am still experiencing errors when the Common Table Expression (CTE) is explicitly named "stream."

### Sample Code
```
CREATE TABLE foo AS 
WITH stream AS (
    SELECT * FROM bar
)
SELECT * FROM stream;
```

### Error Message
`sqlglot.errors.ParseError: Required keyword: 'this' missing for <class 'sqlglot.expressions.Stream'>.`





repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_databricks.py b/tests/dialects/test_databricks.py
index 1dbbfa9a..d0090b9e 100644
--- a/tests/dialects/test_databricks.py
+++ b/tests/dialects/test_databricks.py
@@ -7,6 +7,7 @@ class TestDatabricks(Validator):
     dialect = "databricks"
 
     def test_databricks(self):
+        self.validate_identity("SELECT * FROM stream")
         self.validate_identity("SELECT t.current_time FROM t")
         self.validate_identity("ALTER TABLE labels ADD COLUMN label_score FLOAT")
         self.validate_identity("DESCRIBE HISTORY a.b")
task: metadata: install: pip install -e .
patch: diff --git a/sqlglot/generator.py b/sqlglot/generator.py
index b569e123..bb4d6764 100644
--- a/sqlglot/generator.py
+++ b/sqlglot/generator.py
@@ -630,6 +630,8 @@ class Generator:
 
     def lateral_sql(self, expression):
         this = self.sql(expression, "this")
+        if isinstance(expression.this, exp.Subquery):
+            return f"LATERAL{self.sep()}{this}"
         op_sql = self.seg(
             f"LATERAL VIEW{' OUTER' if expression.args.get('outer') else ''}"
         )
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 63011266..201b2f31 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -1070,8 +1070,12 @@ class Parser:
         if not self._match(TokenType.LATERAL):
             return None
 
-        if not self._match(TokenType.VIEW):
-            self.raise_error("Expected VIEW after LATERAL")
+        subquery = self._parse_select(table=True)
+
+        if subquery:
+            return self.expression(exp.Lateral, this=subquery)
+        elif not self._match(TokenType.VIEW):
+            self.raise_error("Expected subquery or VIEW after LATERAL")
 
         outer = self._match(TokenType.OUTER)
 
@@ -1105,7 +1109,7 @@ class Parser:
         if not self._match(TokenType.JOIN):
             return None
 
-        kwargs = {"this": self._parse_table()}
+        kwargs = {"this": self._parse_lateral() or self._parse_table()}
 
         if side:
             kwargs["side"] = side.text

problem_statement: [Postgres 14.4] Parser does not support subquery after lateral keyword
Example (valid sql):
```
select art from table1 inner join lateral (select art from table2) table2 on table2.art=table2.art
```
Result:
```
ParseError: Expected table name. Line 1, Col: 35.
  select art from table1 inner join lateral (select art from table2) table2 on table2.art=table2.art;

Required keyword: 'this' missing for <class 'sqlglot.expressions.Table'>. Line 1, Col: 35.
  select art from table1 inner join lateral (select art from table2) table2 on table2.art=table2.art;

Expected VIEW after LATERAL. Line 1, Col: 43.
  select art from table1 inner join lateral (select art from table2) table2 on table2.art=table2.art;

... and 2 more
```
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_dialect.py b/tests/dialects/test_dialect.py
index 658d942b..d81b8b8d 100644
--- a/tests/dialects/test_dialect.py
+++ b/tests/dialects/test_dialect.py
@@ -629,6 +629,14 @@ class TestDialect(Validator):
             },
         )
 
+    def test_lateral_subquery(self):
+        self.validate_identity(
+            "SELECT art FROM tbl1 INNER JOIN LATERAL (SELECT art FROM tbl2) AS tbl2 ON tbl1.art = tbl2.art"
+        )
+        self.validate_identity(
+            "SELECT * FROM tbl AS t LEFT JOIN LATERAL (SELECT * FROM b WHERE b.t_id = t.t_id) AS t ON TRUE"
+        )
+
     def test_set_operators(self):
         self.validate_all(
             "SELECT * FROM a UNION SELECT * FROM b",
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py
index 5b12f56c..eca2bf59 100644
--- a/sqlglot/dialects/dialect.py
+++ b/sqlglot/dialects/dialect.py
@@ -411,6 +411,9 @@ class Dialect(metaclass=_Dialect):
     is cast to x's type to match it instead.
     """
 
+    SUPPORTS_VALUES_DEFAULT = True
+    """Whether the DEFAULT keyword is supported in the VALUES clause."""
+
     REGEXP_EXTRACT_DEFAULT_GROUP = 0
     """The default value for the capturing group."""
 
diff --git a/sqlglot/dialects/presto.py b/sqlglot/dialects/presto.py
index ec702a09..056d974c 100644
--- a/sqlglot/dialects/presto.py
+++ b/sqlglot/dialects/presto.py
@@ -198,6 +198,7 @@ class Presto(Dialect):
     TYPED_DIVISION = True
     TABLESAMPLE_SIZE_IS_PERCENT = True
     LOG_BASE_FIRST: t.Optional[bool] = None
+    SUPPORTS_VALUES_DEFAULT = False
 
     TIME_MAPPING = MySQL.TIME_MAPPING
 
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 2a477d9b..12419e8c 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -2946,8 +2946,13 @@ class Parser(metaclass=_Parser):
         )
 
     def _parse_value(self) -> t.Optional[exp.Tuple]:
+        def _parse_value_expression() -> t.Optional[exp.Expression]:
+            if self.dialect.SUPPORTS_VALUES_DEFAULT and self._match(TokenType.DEFAULT):
+                return exp.var(self._prev.text.upper())
+            return self._parse_expression()
+
         if self._match(TokenType.L_PAREN):
-            expressions = self._parse_csv(self._parse_expression)
+            expressions = self._parse_csv(_parse_value_expression)
             self._match_r_paren()
             return self.expression(exp.Tuple, expressions=expressions)
 

problem_statement: “Default” is a keyword, but it was converted into a string value after translation.
```
Python 3.13.0 | packaged by Anaconda, Inc. | (main, Oct  7 2024, 16:25:56) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlglot
>>> sqlglot.transpile("insert into t(i) values (default)", read="mysql", write="duckdb")[0]
'INSERT INTO t (i) VALUES ("default")'
```


“Default” is a keyword, but it was converted into a string value after translation.
repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_mysql.py b/tests/dialects/test_mysql.py
index fd6b36f1..9e5b74e0 100644
--- a/tests/dialects/test_mysql.py
+++ b/tests/dialects/test_mysql.py
@@ -118,6 +118,13 @@ class TestMySQL(Validator):
             "CREATE TABLE `foo` (a VARCHAR(10), INDEX idx_a (a DESC))",
         )
 
+        self.validate_all(
+            "insert into t(i) values (default)",
+            write={
+                "duckdb": "INSERT INTO t (i) VALUES (DEFAULT)",
+                "mysql": "INSERT INTO t (i) VALUES (DEFAULT)",
+            },
+        )
         self.validate_all(
             "CREATE TABLE t (id INT UNSIGNED)",
             write={
task: metadata: install: pip install -e .[dev]
patch: diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 7f310b3b..ae3f6cde 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -5902,7 +5902,7 @@ class Parser(metaclass=_Parser):
         )
 
     def _parse_primary_key_part(self) -> t.Optional[exp.Expression]:
-        return self._parse_field()
+        return self._parse_ordered() or self._parse_field()
 
     def _parse_period_for_system_time(self) -> t.Optional[exp.PeriodForSystemTimeConstraint]:
         if not self._match(TokenType.TIMESTAMP_SNAPSHOT):

problem_statement: TSQL: PRIMARY KEY constraint fails to parse if sort option is given
The following CREATE TABLE statement parses just fine:
```
import sqlglot

test = """CREATE TABLE dbo.test (
      id INT,
      name VARCHAR(50),
      CONSTRAINT pk_testTable PRIMARY KEY (id)
      ) ;"""
        
    parsed_script = sqlglot.parse(test, read="tsql")
```

However, when I add ASC or DESC to the PRIMARY KEY constraint, it fails to parse:

```
import sqlglot

test = """CREATE TABLE dbo.test (
    id INT,
    name VARCHAR(50),
    CONSTRAINT pk_testTable PRIMARY KEY (id DESC)
    ) ;"""
        
    parsed_script = sqlglot.parse(test, read="tsql")
```

Error Message:

```
Exception has occurred: ParseError
Expecting ). Line 4, Col: 45.
  bo.test (
        id INT,
        name VARCHAR(50),
        CONSTRAINT pk_testTable PRIMARY KEY (id [4mDESC[0m)
        ) ;
  File "C:\*snip*\main.py", line 96, in main
    parsed_script = sqlglot.parse(test, read="tsql")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\*snip*\main.py", line 116, in <module>
    main()
sqlglot.errors.ParseError: Expecting ). Line 4, Col: 45.
  bo.test (
        id INT,
        name VARCHAR(50),
        CONSTRAINT pk_testTable PRIMARY KEY (id [4mDESC[0m)
        ) ;
```

Official Documentation: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-ver16#constraint

Edit: sqlglot version is 25.21.3.

repo: tobymao/sqlglot
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index 738120a2..fe1aa9c5 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -436,6 +436,13 @@ class TestTSQL(Validator):
             "'a' + 'b'",
         )
 
+        self.validate_identity(
+            "CREATE TABLE db.t1 (a INTEGER, b VARCHAR(50), CONSTRAINT c PRIMARY KEY (a DESC))",
+        )
+        self.validate_identity(
+            "CREATE TABLE db.t1 (a INTEGER, b INTEGER, CONSTRAINT c PRIMARY KEY (a DESC, b))"
+        )
+
     def test_option(self):
         possible_options = [
             "HASH GROUP",