title: Groovy Sql Paging Behavior
body: <p>I am using the groovy.sql.Sql class to query a database and process the results. My problem is that the ResultSet can be very large; so large that I risk running out of memory if I try to process the whole ResultSet at once. I know the Sql.rows() method supports paging using offset and max results parameters but I haven't been able to find a good example of how to use it (and I'm not certain that paging is what I'm looking for).</p>
  
  <p>Basically, here's what I'm trying to do:</p>
  
  <pre><code>def endOfResultSet = false
  for(int x = 1; !endOfResultSet; x+=1000){
      def result = sql.rows("Select * from table", x, 1000)
      processResult(result)
      endOfResultSet = result.size()!=1000
  }
  </code></pre>
  
  <p>My question is if Groovy is smart enough to reuse the same result set for the <code>sql.rows("Select * from table", x, 1000)</code> call or if it will be repeatedly be running the same statement on the database and then paging to where the offset starts.</p>
  
  <p>Your help is appreciated, Thanks!</p>
  
  <p>Edit: What I'm trying to avoid is running the same query on the database multiple times. I'd like to run the query once, get the first 1,000 rows, process them, get the next 1,000 rows, etc... until all the rows are processed.</p>