Guest User

Untitled

a guest
Jun 3rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import psycopg2.extras
  2.  
  3. try:
  4. conn = psycopg2.connect("user='postgres' host='localhost' password='postgres'",
  5. )
  6. except:
  7. print "I am unable to connect to the database"
  8.  
  9. cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  10.  
  11. cur.execute("""SELECT datname from pg_database""")
  12.  
  13.  
  14. rows = cur.fetchall()
  15. print "nShow me the databases:n"
  16. print rows
  17.  
  18. [['template1'], ['template0'], ['postgres'], ['iip'], ['test'], ['test_postgres'], ['testdb']]
Add Comment
Please, Sign In to add comment