Making list of all tables in public schema and trying to insert row count in csv file , all things are working file but data is not inserting on continues row its skiping row
import psycopg2
import csv
conn=psycopg2.connect(host="localhost",database="practice_db",user="postgres",
password="admin")
print('connected')
cursor=conn.cursor()
cursor.execute("select version()")
print(cursor.fetchall())
sql="select table_name from information_schema.tables where table_type='BASE TABLE' AND TABLE_SCHEMA='public'"
cursor.execute(sql)
list_table=[item[0] for item in cursor.fetchall()]
print(list_table)
with open('python_count_psql.csv','w') as file:
writer=csv.writer(file)
writer.writerow(['Table','Count'])
for row in list_table:
cursor.execute('SELECT COUNT(*) FROM {}'.format(row))
writer.writerow([row,cursor.fetchone()[0]])