Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(duckdb): handle view deletion in drop_table to prevent catalog er…
…rors
  • Loading branch information
Retugbo committed Feb 9, 2026
commit 4e387e7e46a2e05066204034dd1d57f3f04ef92a
21 changes: 21 additions & 0 deletions sqlmesh/core/engine_adapter/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ def _df_to_source_queries(
)
]

def drop_table(
self,
table_name: TableName,
**kwargs: t.Any,
) -> None:
"""
DuckDB will raise an error if you try to DROP TABLE on a view.
We check the object type first to ensure we use the correct command.
"""
table = exp.to_table(table_name)

# Ensure we have a schema name, default to 'main' for DuckDB
schema = table.db or "main"
objects = self._get_data_objects(schema, object_names={table.name})
obj = objects[0] if objects else None

if obj and obj.type.is_view:
return self.drop_view(table_name, **kwargs)

return super().drop_table(table_name, **kwargs)

def _get_data_objects(
self, schema_name: SchemaName, object_names: t.Optional[t.Set[str]] = None
) -> t.List[DataObject]:
Expand Down