Basically what I'm trying to do is use the info schema to generate a dataframe of drop commands that I would then want to iterate through and execute.
import snowflake.snowpark as snowpark
def main(session: snowpark.Session):
drop_commands = session.sql(""" SELECT 'DROP ' || table_type || ' if exists <database>.' || table_schema || '.' || table_name || ';' as drop_command
FROM <database>.INFORMATION_SCHEMA.TABLES
WHERE table_catalog = '<database>'
and table_schema in '<schema>'""").collect()
for iter,row in df:
session.sql(row['drop_command']).collect()
# drop_commands.show()
# Return value will appear in the Results tab.
return drop_commands
I'm expecting that the drop_commands object will return as a data frame and then the loop will iterate through each drop command and drop snowflake object that I tell it to using the query. When I comment out the loop and get rid of the .collect() at the end of the drop_commands definition then I can see the data frame returned in the results... However, this is contradictory to the documentation that Snowflake has available (* .collect() executes the sql *). I've tried different versions of the loop as well because of reading about the differences between a snowpark and pandas data frame to no avail.
Note that I would like to have these snowpark issues addressed regardless of whether there is an easier way to purge certain tables/schemas/databases - however if anyone does know how to do that programmatically that'd be great feedback as well.