title: NPGSQL: Streaming results from Postgres query?
body: <p>I have a large table (2,000,000 rows) and I'd like to print each record to the screen, one at time, without loading the entire table into memory.</p>
  
  <pre><code>//pseudo code
  var cmd = new NpgSQLCommand();
  cmd.CommandText = "SELECT * FROM mytable;"
  IReader reader = cmd.ExecuteReader(); //blocks until the entire set is returned
  
  while(reader.Read()) //ideally each call to read loads more results from the db.
  {
  // print record name
  
  }
  </code></pre>
  
  <p>So as noted in the code above, the ExecuteReader() doesn't continue until the entire set is loaded into memory. How do I change this behavior so the results are streamed?</p>
  
  <p>Thanks</p>
  
  <p>ETA: While this seems like homework, it's not. It's just an easier way to describe a problem that involves reading an entire table with a single query but processing the results a row at a time.</p>
  
  <p>ETA x2:</p>
  
  <p>From npgsql
  Warning: There is a known issue when calling ExecuteReader and large tables. <strike>Currently</strike> Version 1 of Npgsql gets all data from table before returning. If you are experiencing bad performance in such cases, you may need to use a server cursor to page through rows. For that, you can use a code like the following:</p>