Skip to content

Commit bb46ee3

Browse files
authored
fix(parser): Parse exp.Column for DROP COLUMN (#4390)
1 parent e7b67e0 commit bb46ee3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

sqlglot/parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,9 +1738,13 @@ def _parse_drop(self, exists: bool = False) -> exp.Drop | exp.Command:
17381738

17391739
concurrently = self._match_text_seq("CONCURRENTLY")
17401740
if_exists = exists or self._parse_exists()
1741-
table = self._parse_table_parts(
1742-
schema=True, is_db_reference=self._prev.token_type == TokenType.SCHEMA
1743-
)
1741+
1742+
if kind == "COLUMN":
1743+
this = self._parse_column()
1744+
else:
1745+
this = self._parse_table_parts(
1746+
schema=True, is_db_reference=self._prev.token_type == TokenType.SCHEMA
1747+
)
17441748

17451749
cluster = self._parse_on_property() if self._match(TokenType.ON) else None
17461750

@@ -1752,7 +1756,7 @@ def _parse_drop(self, exists: bool = False) -> exp.Drop | exp.Command:
17521756
return self.expression(
17531757
exp.Drop,
17541758
exists=if_exists,
1755-
this=table,
1759+
this=this,
17561760
expressions=expressions,
17571761
kind=self.dialect.CREATABLE_KIND_MAPPING.get(kind) or kind,
17581762
temporary=temporary,

tests/test_parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,8 @@ def test_odbc_date_literals(self):
879879
expr = parse_one(sql)
880880
self.assertIsInstance(expr, exp.Insert)
881881
self.assertIsInstance(expr.expression.expressions[0].expressions[0], cls)
882+
883+
def test_drop_column(self):
884+
ast = parse_one("ALTER TABLE tbl DROP COLUMN col")
885+
self.assertEqual(len(list(ast.find_all(exp.Table))), 1)
886+
self.assertEqual(len(list(ast.find_all(exp.Column))), 1)

0 commit comments

Comments
 (0)