@@ -254,9 +254,11 @@ func (b *Builder) buildDropTable(inScope *scope, c *ast.DDL) (outScope *scope) {
254254 tableScope , ok := b .buildResolvedTableForTablename (inScope , t , nil )
255255 if ok {
256256 // attempting to drop a non-temporary table with DROP TEMPORARY, results in Unknown table
257- if _ , isTmpTbl := tableScope .node .(sql.TemporaryTable ); ! isTmpTbl && c .Temporary {
258- err := sql .ErrUnknownTable .New (tableName )
259- b .handleErr (err )
257+ if tbl , ok := tableScope .node .(sql.Table ); ok {
258+ if tmpTbl := getTempTable (tbl ); tmpTbl != nil && ! tmpTbl .IsTemporary () && c .Temporary {
259+ err := sql .ErrUnknownTable .New (tableName )
260+ b .handleErr (err )
261+ }
260262 }
261263 dropTables = append (dropTables , tableScope .node )
262264 } else if ! c .IfExists {
@@ -269,6 +271,19 @@ func (b *Builder) buildDropTable(inScope *scope, c *ast.DDL) (outScope *scope) {
269271 return
270272}
271273
274+ func getTempTable (t sql.Table ) sql.TemporaryTable {
275+ switch t := t .(type ) {
276+ case sql.TemporaryTable :
277+ return t
278+ case sql.TableWrapper :
279+ return getTempTable (t .Underlying ())
280+ case * plan.ResolvedTable :
281+ return getTempTable (t .Table )
282+ default :
283+ return nil
284+ }
285+ }
286+
272287func (b * Builder ) buildTruncateTable (inScope * scope , c * ast.DDL ) (outScope * scope ) {
273288 outScope = inScope .push ()
274289 tableScope , ok := b .buildResolvedTableForTablename (inScope , c .Table , nil )
0 commit comments