diff --git a/clients/snowflake/staging.go b/clients/snowflake/staging.go index b09851d6c..67b440a21 100644 --- a/clients/snowflake/staging.go +++ b/clients/snowflake/staging.go @@ -86,8 +86,9 @@ func (s *Store) PrepareTemporaryTable(ctx context.Context, tableData *optimizati } if _, err = s.Exec(copyCommand); err != nil { - // If COPY INTO failed, we should delete the file from the stage - // We only need to do this for non-temp tables (which would be the case for History mode) because we PURGE = TRUE will only delete the file after a successful COPY INTO + // For non-temp tables, we should try to delete the staging file if COPY INTO fails. + // This is because [PURGE = TRUE] will only delete the staging files upon a successful COPY INTO. + // We also only need to do this for non-temp tables because these staging files will linger, since we create a new temporary table per attempt. if !createTempTable { if _, deleteErr := s.ExecContext(ctx, s.dialect().BuildRemoveAllFilesFromStage(tempTableID.FullyQualifiedName(), "")); deleteErr != nil { slog.Warn("Failed to remove all files from stage", slog.Any("deleteErr", deleteErr))