Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
- try:
- conn = psycopg2.connect("dbname='db1' user='egor0' host='localhost' password=''")
- except:
- print ("I am unable to connect to the database")
- conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
- conn.autocommit = True
- cur = conn.cursor()
- cur.execute("""SELECT datname from pg_database""")
- rows = cur.fetchall()
- for row in rows:
- print(row[0])
- cur.execute("""DROP DATABASE db1""")
Add Comment
Please, Sign In to add comment