Repository: tobymao/sqlglot

Issue:
Oracle: ALTER TABLE x DROP PRIMARY KEY parse error
```
sqlglot.errors.ParseError: Expected table name but got <Token token_type: TokenType.PRIMARY_KEY, text: PRIMARY KEY, line: 3, col: 6, end: 37, comments: []>. Line 3, Col: 6.
  
alter table bicikli
drop primary key;
     ^^^^^^^^^^^
```


Discussion:
@GeorgeSittas this is because you assume it's a "COLUMN" in def_parse_drop_column

i'm not sure why you needed this 

f57bdd4ad
That commit seems outdated, see latest version: https://github.com/tobymao/sqlglot/blob/main/sqlglot/parser.py#L3934. The problem is actually related to the `primary key` token; it chokes on the `_parse_table` method:

```python
  File "/Users/georgesittas/Code/tobiko/sqlglot/sqlglot/parser.py", line 1042, in _parse_drop
    this=self._parse_table(schema=True),
  File "/Users/georgesittas/Code/tobiko/sqlglot/sqlglot/parser.py", line 2160, in _parse_table
    this = self._parse_table_parts(schema=schema)
  File "/Users/georgesittas/Code/tobiko/sqlglot/sqlglot/parser.py", line 2129, in _parse_table_parts
    self.raise_error(f"Expected table name but got {self._curr}")
  File "/Users/georgesittas/Code/tobiko/sqlglot/sqlglot/parser.py", line 921, in raise_error
    raise error
sqlglot.errors.ParseError: Expected table name but got <Token token_type: TokenType.PRIMARY_KEY, text: PRIMARY KEY, line: 1, col: 26, end: 36, comments: []>. Line 1, Col: 26.
  alter table bicikli drop primary key
                           ~~~~~~~
```

Resolving patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -1025,16 +1025,13 @@ def _parse_statement(self) -> t.Optional[exp.Expression]:
         self._parse_query_modifiers(expression)
         return expression
 
-    def _parse_drop(self, default_kind: t.Optional[str] = None) -> t.Optional[exp.Expression]:
+    def _parse_drop(self) -> t.Optional[exp.Expression]:
         start = self._prev
         temporary = self._match(TokenType.TEMPORARY)
         materialized = self._match(TokenType.MATERIALIZED)
         kind = self._match_set(self.CREATABLES) and self._prev.text
         if not kind:
-            if default_kind:
-                kind = default_kind
-            else:
-                return self._parse_as_command(start)
+            return self._parse_as_command(start)
 
         return self.expression(
             exp.Drop,
@@ -3932,7 +3929,10 @@ def _parse_add_column(self) -> t.Optional[exp.Expression]:
         return expression
 
     def _parse_drop_column(self) -> t.Optional[exp.Expression]:
-        return self._match(TokenType.DROP) and self._parse_drop(default_kind="COLUMN")
+        drop = self._match(TokenType.DROP) and self._parse_drop()
+        if drop and not isinstance(drop, exp.Command):
+            drop.set("kind", drop.args.get("kind", "COLUMN"))
+        return drop
 
     # https://docs.aws.amazon.com/athena/latest/ug/alter-table-drop-partition.html
     def _parse_drop_partition(self, exists: t.Optional[bool] = None) -> 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
@@ -739,6 +739,7 @@ ALTER TABLE IF EXISTS integers ADD COLUMN k INT
 ALTER TABLE integers ADD COLUMN l INT DEFAULT 10
 ALTER TABLE measurements ADD COLUMN mtime TIMESTAMPTZ DEFAULT NOW()
 ALTER TABLE integers DROP COLUMN k
+ALTER TABLE integers DROP PRIMARY KEY
 ALTER TABLE integers DROP COLUMN IF EXISTS k
 ALTER TABLE integers DROP COLUMN k CASCADE
 ALTER TABLE integers ALTER COLUMN i TYPE VARCHAR
diff --git a/tests/test_transpile.py b/tests/test_transpile.py
--- a/tests/test_transpile.py
+++ b/tests/test_transpile.py
@@ -322,7 +322,6 @@ def test_alter(self):
             "ALTER TABLE integers ADD k INTEGER",
             "ALTER TABLE integers ADD COLUMN k INT",
         )
-        self.validate("ALTER TABLE integers DROP k", "ALTER TABLE integers DROP COLUMN k")
         self.validate(
             "ALTER TABLE integers ALTER i SET DATA TYPE VARCHAR",
             "ALTER TABLE integers ALTER COLUMN i TYPE VARCHAR",