title: Using Psycopg2 to call a Postgres procedure that returns a record
body: <p>I have a Postgres procedure whose return type is <code>SETOF record</code>. The procedure takes several parameters, including one parameter which is a list and two which are datetimes. I would like to call this procedure from psycopg2. I am getting this error message:</p>
  
  <p><code>a column definition list is required for functions returning "record"</code></p>
  
  <p>We would like the columns returned from the stored proc to be dynamic (based on user input), so we don't want to use out parameters, RETURN TABLE, RETURN SETOF , or anything else that requires declaring the return type at procedure definition time. The only way to make the return columns dynamic was this:</p>
  
  <p><a href="https://stackoverflow.com/a/6085167/75857">https://stackoverflow.com/a/6085167/75857</a></p>
  
  <p>What is the best way of using psycopg to call a stored proc that returns a set of records? We came up with this code which seems to work, but not sure if its recommended:</p>
  
  <p><code>cursor.execute("SELECT * FROM get_fnord(%s, %s, %s) as (foo integer, bar integer)", ([12561], start, end));</code></p>