cursor.fetchmany vs DECLARE BINARY CURSOR and FETCH <p>I am not sure which is the most effective or the disadvantages/advantages of each approach or whether they are technically the same thing ?</p> <p>That is </p> <pre><code>cursor.execute("DECLARE super_cursor BINARY CURSOR FOR SELECT names FROM myTable") while True: cursor.execute("FETCH 1000 FROM super_cursor") rows = cursor.fetchall() </code></pre> <p>as expressed in the answer given by alecxe <a href="http://stackoverflow.com/questions/17933344/python-postgres-can-i-ftechall-1-million-rows">python postgres can I ftechall() 1 million rows?</a></p> <p>In comparison to: </p> <pre><code>while True: results = cursor.fetchmany(1000) if not results: break for result in results: yield result </code></pre> <p>Should one use fetchmany as specified in psycopg2 or DECLARE BINARY.</p> <p>I Have assumed that fetchmany and DECLARE BINARY both setup a temporary table on the database server side... The client side is an Apache server.</p> <p>The website I am working with does calculations on user input to that of data in the database... Hence needs to load large amounts of data for pattern matching. </p> <p>Thank you.</p>