import psycopg2
def list_all_tables():
conn = psycopg2.connect(database="your_database", user="your_user",
password="your_password", host="your_host", port="your_port")
cur = conn.cursor()
# Execute SQL command to get all table names
cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE';")
tables = cur.fetchall()
table_names = [table[0] for table in tables]
# Print all table names
for table_name in table_names:
print(table_name)
# Close communication with the PostgreSQL database
cur.close()
conn.close()
# Call the function to list all tables
list_all_tables()