xxxxxxxxxx
SELECT schema_name
FROM information_schema.schemata;
xxxxxxxxxx
import psycopg2
# Connect to the database
conn = psycopg2.connect(
host="your_host",
database="your_database",
user="your_user",
password="your_password"
)
# Create a cursor object
cur = conn.cursor()
# Execute the query to get the list of schemas
cur.execute("SELECT schema_name FROM information_schema.schemata")
# Fetch all the rows from the result set
schemas = cur.fetchall()
# Print the list of schemas
for schema in schemas:
print(schema[0])
# Close the cursor and connection
cur.close()
conn.close()