Query PostgreSQL database with select statement : PostgreSQL : Database PYTHON TUTORIALS


PYTHON TUTORIALS » Database » PostgreSQL »

 

Query PostgreSQL database with select statement


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()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Database
» PostgreSQL