File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
sqlmesh/core/engine_adapter Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,27 @@ def _df_to_source_queries(
9696 )
9797 ]
9898
99+ def drop_table (
100+ self ,
101+ table_name : TableName ,
102+ ** kwargs : t .Any ,
103+ ) -> None :
104+ """
105+ DuckDB will raise an error if you try to DROP TABLE on a view.
106+ We check the object type first to ensure we use the correct command.
107+ """
108+ table = exp .to_table (table_name )
109+
110+ # Ensure we have a schema name, default to 'main' for DuckDB
111+ schema = table .db or "main"
112+ objects = self ._get_data_objects (schema , object_names = {table .name })
113+ obj = objects [0 ] if objects else None
114+
115+ if obj and obj .type .is_view :
116+ return self .drop_view (table_name , ** kwargs )
117+
118+ return super ().drop_table (table_name , ** kwargs )
119+
99120 def _get_data_objects (
100121 self , schema_name : SchemaName , object_names : t .Optional [t .Set [str ]] = None
101122 ) -> t .List [DataObject ]:
You can’t perform that action at this time.
0 commit comments