I am using psycopg2 to connect to Postgres database and return query results on the screen using Python. I can only return one column of data, not many columns like PSQL does. Please see my code. Where did I do wrong?
Your kind response would be greatly appreciated.
#!/usr/bin/python
import psycopg2
CONNSTR = """
host=localhost
dbname=wa
user=super
password=test
port=5432"""
cxn = psycopg2.connect(CONNSTR)
cur = cxn.cursor()
cur.execute("""SELECT procpid,usename,current_query FROM pg_stat_activity;""")
rows = cur.fetchall()
print "\nShow me the query results:\n"
for row in rows:
print " ", row[1]