title: Elegant PostgreSQL Group by for Ruby on Rails / ActiveRecord
body: <p>Trying to retrieve an array of ActiveRecord Objects grouped by date with PostgreSQL.</p>
  
  <p>More specifically I'm trying to translate the following MySQL query:</p>
  
  <pre><code>@posts = Post.all(:group =&gt; "date(date)", 
     :conditions =&gt; ["location_id = ? and published = ?", @location.id, true], 
     :order =&gt; "created_at DESC")
  </code></pre>
  
  <p>I am aware that PostgreSQL interpretation of the SQL standard is stricter than MySQL and that consequently this type of query won't work...and have read a number of posts on StackOverflow and elsewhere on the subject - but none of them seem to be the definitive answer on this subject</p>
  
  <p>I've tried various combinations of queries with group by and distinct clauses without much joy - and for the moment I have a rather inelegant hack which although works makes me blush when I look at it. </p>
  
  <p>What is the proper way to make such a query with Rails and PostgreSQL ? (Ignoring the fact that surely this should be abstracted away at the ActiveRecord Level)</p>