I am having bit of trouble with the psycopg2 Python module. I wrote a small code to extract some information from PostgreSQL table using psycopg2 module. I want to know the data type for each columns in the table:
import os, psycopg2, getpass, sys, string
userpass = getpass.getpass()
# Connect to the database
conn = psycopg2.connect("host=hostname dbname=db user=username password=%s" % (userpass))
cur = conn.cursor()
cur.execute("SELECT * FROM database.table;")
fieldTypes = [desc[1] for desc in cur.description]
print fieldTypes
When I execute this code, I get a list of integers (i.e. OIDs). Is there a way to convert this into something that's more understandable (e.g. 'str','int','bool' and so forth).