2021年4月6日星期二

ProgrammingError: no results to fetch when using fetchall on cursor

I am using psycopg2 with Redshift.

When I try to execute the following code, I get: ProgrammingError: no results to fetch

I am a bit stuck on why cur_cursor.fetchall() is not returning results.

 def execute_and_fetch(self, sql):          self.execute(sql)          cur_cursor = self.get_cursor()          try:              results = []              for row in cur_cursor.fetchall():                  results.append(row)  

sql variable is 'select * from pg_table_def' . It has also failed with any other sql query I have tried. the get_cursor method is below and I believe is working correctly.

    def get_cursor(self):          if not hasattr(thread_local, 'cursor'):              setattr(thread_local, 'cursor', self._connection())          return getattr(thread_local, 'cursor')  
https://stackoverflow.com/questions/66977966/programmingerror-no-results-to-fetch-when-using-fetchall-on-cursor April 07, 2021 at 08:02AM

没有评论:

发表评论