Guest User

Untitled

a guest
Jun 9th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. import psycopg2
  2. from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
  3.  
  4. try:
  5. conn = psycopg2.connect("dbname='db1' user='egor0' host='localhost' password=''")
  6.  
  7. except:
  8. print ("I am unable to connect to the database")
  9. conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
  10. conn.autocommit = True
  11. cur = conn.cursor()
  12. cur.execute("""SELECT datname from pg_database""")
  13. rows = cur.fetchall()
  14. for row in rows:
  15. print(row[0])
  16.  
  17.  
  18.  
  19. cur.execute("""DROP DATABASE db1""")
Add Comment
Please, Sign In to add comment