I am getting an issue here:
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
sql = """
SELECT DISTINCT (tenor_years)
FROM bond_pnl
WHERE country = '%s'
""" % country
cursor.execute(sql)
print(cursor.fetchall())
print(cursor.rowcount)
It gives the following output:
[]
11
which means that cursor.rowcount is 11 but cursor.fetchall() is empty list. I have already tried doing this:
conn.set_session(readonly=True, autocommit=True)
and this solution as well :Click to see
Any help regarding this will be appreciated.
EDIT: Just came across another thing, this code when executed first time, works fine. But executing it again(second, third, ...n execution) gives the above behavior.