Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #!/var/bin/python
  2. import psycopg2
  3. import psycopg2.extras
  4.  
  5. def get_dict_resultset(sql):
  6. conn = psycopg2.connect("dbname=pem host=localhost user=postgres password=Drupal#1008")
  7. cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  8. cur.execute (sql)
  9. ans =cur.fetchall()
  10. dict_result = []
  11. for row in resultset:
  12. dict_result.append(dict(row))
  13. return dict_result
  14.  
  15. sql = """select * from tablename"""
  16. return get_dict_resultset(sql)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement