Skip to content
Draft
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
20 changes: 20 additions & 0 deletions sqlmesh/core/engine_adapter/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,23 @@ def _create_table(
@property
def _is_motherduck(self) -> bool:
return self._extra_config.get("is_motherduck", False)

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.
Fallback to DROP VIEW if the execution of DROP TABLE fails.
"""
from duckdb import Error

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

try:
super().drop_table(table_name, exists=exists, **kwargs)
except Error:
self.drop_view(table_name, **kwargs)