Advertisement
Guest User

Untitled

a guest
May 30th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. cursor.description
  2.  
  3. import psycopg2
  4.  
  5. if __name__ == '__main__':
  6. DSN = 'host=HOST port=PORT dbname=DBNAME user=USER password=PASS'
  7.  
  8. with psycopg2.connect(DSN) as connection:
  9. with connection.cursor() as cursor:
  10. cursor.execute("SELECT * FROM TABLE_NAME LIMIT 0")
  11. for i in cursor.description:
  12. cursor.execute("SELECT typname FROM pg_type WHERE oid={oid}".format(oid=i[1]))
  13. print("Column name: ", i[0], " Column type: ", cursor.fetchone()[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement