Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/var/bin/python
- import psycopg2
- import psycopg2.extras
- def get_dict_resultset(sql):
- conn = psycopg2.connect("dbname=pem host=localhost user=postgres password=Drupal#1008")
- cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
- cur.execute (sql)
- ans =cur.fetchall()
- dict_result = []
- for row in resultset:
- dict_result.append(dict(row))
- return dict_result
- sql = """select * from tablename"""
- return get_dict_resultset(sql)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement