#!/usr/bin/python # Replace , , and below with your actual DB, user, and password. import psycopg2 import sys con = None try: con = psycopg2.connect(database='', user='', password='') cur = con.cursor() cur.execute("SELECT * FROM testschema.testtable") rows = cur.fetchall() for row in rows: print row except psycopg2.DatabaseError, e: print 'Error %s' % e sys.exit(1) finally: if con: con.close()