Database Python Tutorial

import psycopg
dbh = psycopg.connect('dbname=dbname user=user')
print "Connection successful."
cur = dbh.cursor()
cur.execute("SELECT * FROM myTable")
    
for column in cur.description:
    name, type_code, display_size, internal_size, precision, scale, null_ok = column
    
    print "Column name:", name
    print "Type code:", type_code
    print "Display size:", display_size
    print "Internal size:", internal_size
    print "Precision:", precision
    print "Scale:", scale
    print "Null OK:", null_ok
    print
dbh.close()