moj-analytical-services / pydbtools

Python version of dbtools
https://moj-analytical-services.github.io/pydbtools/
10 stars 2 forks source link

Feature delete table only #105

Open mshodge opened 1 year ago

mshodge commented 1 year ago

New function feature to mimic awswrangler.catalog.delete_table_if_exists - so we can delete the table only but keep the S3 data (similar to an SQL query of DROP TABLE IF EXISTS [TABLE_NAME]).

def delete_table(table: str, database: str, boto3_session=None):
    """
    Deletes a table from an Athena database.

    Args:
        table (str): The table name to drop.
        database (str): The database name.

    Returns:
        True if table exists and is deleted, False if table
        does not exist
    """

    if table in list(tables(database=database, limit=None)["Table"]):
        wr.catalog.delete_table_if_exists(
            database=database, table=table, boto3_session=boto3_session
        )
        return True
    else:
        return False

Have updated the README.md and CHANGELOG.md too.