Skip to content

Commit

Permalink
fix(parser): Parse exp.Column for DROP COLUMN (#4390)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaggelisD authored Nov 14, 2024
1 parent e7b67e0 commit bb46ee3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1738,9 +1738,13 @@ def _parse_drop(self, exists: bool = False) -> exp.Drop | exp.Command:

concurrently = self._match_text_seq("CONCURRENTLY")
if_exists = exists or self._parse_exists()
table = self._parse_table_parts(
schema=True, is_db_reference=self._prev.token_type == TokenType.SCHEMA
)

if kind == "COLUMN":
this = self._parse_column()
else:
this = self._parse_table_parts(
schema=True, is_db_reference=self._prev.token_type == TokenType.SCHEMA
)

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

Expand All @@ -1752,7 +1756,7 @@ def _parse_drop(self, exists: bool = False) -> exp.Drop | exp.Command:
return self.expression(
exp.Drop,
exists=if_exists,
this=table,
this=this,
expressions=expressions,
kind=self.dialect.CREATABLE_KIND_MAPPING.get(kind) or kind,
temporary=temporary,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,8 @@ def test_odbc_date_literals(self):
expr = parse_one(sql)
self.assertIsInstance(expr, exp.Insert)
self.assertIsInstance(expr.expression.expressions[0].expressions[0], cls)

def test_drop_column(self):
ast = parse_one("ALTER TABLE tbl DROP COLUMN col")
self.assertEqual(len(list(ast.find_all(exp.Table))), 1)
self.assertEqual(len(list(ast.find_all(exp.Column))), 1)

0 comments on commit bb46ee3

Please sign in to comment.