generate functionTue, 14 Feb 2023

1.process each row from csv which have columns "Schema_name","table_name","Type_of_deletion","Time_value","Operation_keyword","Date_column" 2.validate the table existence by using "table_name" = "Schema_name" + "table_name" 3.check "Operation_keyword" value if value is 'Table' we need to drop table other wise cleanup the table

import csv import psycopg2 import psycopg2.extras def get_row(input_file, separator): with open(input_file, 'r') as data: reader = csv.DictReader(data, delimiter=separator) for row in reader: yield row def validate_table_existance(tablename, conn): cur = conn.cursor() sql = """ select count(*) as count_tb from information_schema.tables where table_name = '{0}' """.format(tablename) cur.execute(sql) res = cur.fetchone() if res['count_tb'] == 1: return True else: return False def drop_table(tablename, conn): cur = conn.cursor() sql = """ drop table {0} cascade """.format(tablename) cur.execute(sql) conn.

Questions about programming?Chat with your personal AI assistant