title: call stored procedure in python using cursor
body: <p>The data in the redshift will be changed whenever there is new table schema added in the database. I am trying to fetch all the table_schema names in the information_schema.tables.</p>
  <p>So I have created a stored procedure that returns a distinct table_schema name using cursor method. Now i would like it to call in my project using python.</p>
  <p>Stored Procedure:</p>
  <pre><code>CREATE OR REPLACE PROCEDURE get_dist_schema(rsout INOUT refcursor)
  AS $$
  BEGIN 
    OPEN rsout FOR SELECT DISTINCT table_schema FROM information_schema.tables;
  END;
  $$ LANGUAGE plpgsql;
  
  //this is used in the database to fetch all rows
  BEGIN;
  CALL get_dist_schema('sname');
  FETCH ALL FROM sname;
  
  commit;
  </code></pre>
  <p>python.py</p>
  <pre><code>def call_dist_name(sname):
      conn = None
  
      try:
          params = config()
          conn = psycopg2.connect(**params)
          cur = conn.cursor()
  
          cur.execute('CALL get_dist_schema(%s)' % sname)
  
          conn.commit()
          result = cur.fetchall()
          for row in result:
                  print(row[0])
          cur.close()
  
  
  
      except(Exception, psycopg2.DatabaseError) as error:
          print(error)
  
      finally:
          if conn is not None:
              conn.close()    
  
  
  if __name__ == '__main__':
      call_dist_name('sname')
  </code></pre>
  <p>Error: column &quot;sname&quot; does not exist.</p>
  <p>How do I get the display result set in the stored procedure in my project?</p>