Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cursor.description
- import psycopg2
- if __name__ == '__main__':
- DSN = 'host=HOST port=PORT dbname=DBNAME user=USER password=PASS'
- with psycopg2.connect(DSN) as connection:
- with connection.cursor() as cursor:
- cursor.execute("SELECT * FROM TABLE_NAME LIMIT 0")
- for i in cursor.description:
- cursor.execute("SELECT typname FROM pg_type WHERE oid={oid}".format(oid=i[1]))
- print("Column name: ", i[0], " Column type: ", cursor.fetchone()[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement