import psycopg2
from contextlib import closing
import inspect
db = psycopg2.connect(<credentials>)
query = "SELCT * FROM \
<tablename> \
LIMIT 100;"
with closing(db.cursor()) as cur:
cur.execute(query)
results = cur.fetchall()
print(len(results))
db.close()
With the above simple query and code, I am trying to read results from a SELECT query but the results object always have a single record instead of all. Query is working fine in pgadmin query tool, how do I fix this? Thanks in advance for any suggestions here.
Edit #1 (for snakecharmerb): While checking / printing results, I am always getting a single row correctly giving the query results.
Edit #2 (for Expurple): Thanks for the suggestion, will try that. I believe that is not affecting the overall query result.