Repository: tobymao/sqlglot

Issue:
Error in json_extract_path with "indirect field name"
**Before you file an issue**
dialect is postgresql for reading and writing the query

**Fully reproducible code snippet**
The sql `JSON_ARRAY_ELEMENTS(issues.fields -> custom_fields.field_id )` transpiles as 
`JSON_ARRAY_ELEMENTS(JSON_EXTRACT_PATH(issues.fields, custom_fields).field_id)` which leads to an error because of the incorrect parenthesis.

I would expect this instead : `JSON_ARRAY_ELEMENTS(JSON_EXTRACT_PATH(issues.fields, custom_fields.field_id))`

The full query is
```
WITH issues AS (
    SELECT
        id AS ticket_id,
        fields,
        sync_at
    FROM "source"."issues"
),

custom_fields (field_id) AS (
    VALUES
    ('customfield_10129'),
    ('customfield_10131'),
    ('customfield_10132')
)

SELECT
    issues.ticket_id,
    field.value ->> 'value' AS "value",
    issues.sync_at
FROM issues
    CROSS JOIN custom_fields
    CROSS JOIN LATERAL JSON_ARRAY_ELEMENTS(issues.fields -> custom_fields.field_id ) AS field
WHERE issues.fields -> custom_fields.field_id IS NOT NULL
```

And `sqlglot.transpile(sql, read="postgres", write="postgres")` produces
```
['WITH issues AS (SELECT id AS ticket_id, fields, sync_at FROM "source"."issues"), custom_fields(field_id) AS (SELECT * FROM (VALUES (\'customfield_10129\'), (\'customfield_10131\'), (\'customfield_10132\')) AS _values) SELECT issues.ticket_id, field.value ->> \'value\' AS "value", issues.sync_at FROM issues CROSS JOIN custom_fields CROSS JOIN LATERAL JSON_ARRAY_ELEMENTS(JSON_EXTRACT_PATH(issues.fields, custom_fields).field_id) AS field WHERE NOT JSON_EXTRACT_PATH(issues.fields, custom_fields).field_id IS NULL']
```

Discussion:

Solution patch:
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py
index 5a7c20f371..d56201fd0b 100644
--- a/sqlglot/dialects/duckdb.py
+++ b/sqlglot/dialects/duckdb.py
@@ -1065,3 +1065,7 @@ def numbertostr_sql(self, expression: exp.NumberToStr) -> str:
 
             self.unsupported("Only integer formats are supported by NumberToStr")
             return self.function_fallback_sql(expression)
+
+        def autoincrementcolumnconstraint_sql(self, _) -> str:
+            self.unsupported("The AUTOINCREMENT column constraint is not supported by DuckDB")
+            return ""
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 4872adc9f2..527ec84935 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -5345,6 +5345,8 @@ def _parse_column_ops(self, this: t.Optional[exp.Expression]) -> t.Optional[exp.
                     self.raise_error("Expected type")
             elif op and self._curr:
                 field = self._parse_column_reference() or self._parse_bracket()
+                if isinstance(field, exp.Column) and self._match(TokenType.DOT, advance=False):
+                    field = self._parse_column_ops(field)
             else:
                 field = self._parse_field(any_token=True, anonymous_func=True)
 


Test patch:
diff --git a/tests/dialects/test_postgres.py b/tests/dialects/test_postgres.py
index f84a7fd709..4472bcb21f 100644
--- a/tests/dialects/test_postgres.py
+++ b/tests/dialects/test_postgres.py
@@ -345,6 +345,28 @@ def test_postgres(self):
             "CAST(x AS INT8)",
             "CAST(x AS BIGINT)",
         )
+        self.validate_identity(
+            """
+            WITH
+              json_data AS (SELECT '{"field_id": [1, 2, 3]}'::JSON AS data),
+              field_ids AS (SELECT 'field_id' AS field_id)
+
+            SELECT
+                JSON_ARRAY_ELEMENTS(json_data.data -> field_ids.field_id) AS element
+            FROM json_data, field_ids
+            """,
+            """WITH json_data AS (
+  SELECT
+    CAST('{"field_id": [1, 2, 3]}' AS JSON) AS data
+), field_ids AS (
+  SELECT
+    'field_id' AS field_id
+)
+SELECT
+  JSON_ARRAY_ELEMENTS(JSON_EXTRACT_PATH(json_data.data, field_ids.field_id)) AS element
+FROM json_data, field_ids""",
+            pretty=True,
+        )
 
         self.validate_all(
             "SELECT ARRAY[]::INT[] AS foo",
diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index 12b7c8fae3..6bcb967dbc 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -299,6 +299,13 @@ def test_snowflake(self):
             "SELECT * RENAME (a AS b), c AS d FROM xxx",
         )
 
+        self.validate_all(
+            "CREATE TABLE test_table (id NUMERIC NOT NULL AUTOINCREMENT)",
+            write={
+                "duckdb": "CREATE TABLE test_table (id DECIMAL(38, 0) NOT NULL)",
+                "snowflake": "CREATE TABLE test_table (id DECIMAL(38, 0) NOT NULL AUTOINCREMENT)",
+            },
+        )
         self.validate_all(
             "SELECT TO_TIMESTAMP('2025-01-16 14:45:30.123', 'yyyy-mm-DD hh24:mi:ss.ff6')",
             write={