def create_temp_table(table: Table, connection) -> int: create_query = table.get_query_with_dist_sort_keys() grant_select = table.load_grant_select_statements() full_query = f""" drop table if exists {table.name}{temp_postfix}; {create_query} {grant_select}; """ try: with connection.cursor() as cursor: cursor.execute(full_query) except psycopg2.ProgrammingError as e: raise TableCreationError(table, str(e)) return arrow.now().timestamp