Wondering how life would be much easier if you could get the query resultset to be a dictionary and you could get the value by using a keyword on the dictionary. psycopg2 by default returns resultset as a tuple so you have to use row, etc to get the values. In order to use row[‘column_name’] from the result, you’ll have to use the extras module provided in the psycopg2. Initiate the cursor accordingly and you’ll be able to get the results in form of dictionary.
#!/usr/bin/python import psycopg2 import psycopg2.extras DB_CONNECTION_STRING = "host=%s dbname=%s user=%s password=%s" % (DB_HOST, DB_DATABASE, DB_USER, DB_PASSWORD) dbConn = psycopg2.connect(DB_CONNECTION_STRING) cur = dbConn.cursor(cursor_factory = psycopg2.extras.DictCursor) qSelect = "SELECT server, data, report_date FROM kw_server_raw WHERE processed = FALSE" cur.execute(qSelect) results = cur.fetchall() for row in results: print row['server']