title: Return every nth row from database using ActiveRecord in rails
body: <p>Ruby 1.9.2 / rails 3.1 / deploy onto heroku --> posgresql</p>
  
  <p>Hi, Once a number of rows relating to an object goes over a certain amount, I wish to pull back every nth row instead. It's simply because the rows are used (in part) to display data for graphing, so once the number of rows returned goes above say 20, it's good to return every second one, and so forth.</p>
  
  <p>This question seemed to point in the right direction:
  <a href="https://stackoverflow.com/questions/3147529/activerecord-find-skipping-records-or-getting-every-nth-record">ActiveRecord Find - Skipping Records or Getting Every Nth Record</a></p>
  
  <p>Doing a mod on row number makes sense, but using basically:</p>
  
  <pre><code>@widgetstats = self.widgetstats.find(:all,:conditions =&gt; 'MOD(ROW_NUMBER(),3) = 0 ')
  </code></pre>
  
  <p>doesn't work, it returns an error:</p>
  
  <pre><code>PGError: ERROR:  window function call requires an OVER clause
  </code></pre>
  
  <p>And any attempt to solve that with e.g. basing my OVER clause syntax on things I see in the answer on this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/5537525/row-numbering-in-postgresql">Row numbering in PostgreSQL</a></p>
  
  <p>ends in syntax errors and I can't get a result.</p>
  
  <p>Am I missing a more obvious way of efficiently returning every nth task or if I'm on the right track any pointers on the way to go? Obviously returning all the data and fixing it in rails afterwards is possible, but terribly inefficient.</p>
  
  <p>Thank you!</p>