Skip to content
Open
Changes from all commits
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
25 changes: 25 additions & 0 deletions sqlmesh/core/engine_adapter/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ def _df_to_source_queries(
)
]

def drop_table(
self,
table_name: t.Any,
exists: bool = True,
**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

# Safety: Remove 'exists' from kwargs so we don't pass it twice
kwargs.pop("exists", None)

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

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

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