title: Rails / Postgres: “must appear in the GROUP BY clause or be used in an aggregate function”
body: <p>I'm using this method:</p>
  
  <pre><code>  def self.lines_price_report(n)
      Income.group('date(filled_at)').having("date(filled_at) &gt; ?", Date.today - n).sum(:lines_price)
    end
  </code></pre>
  
  <p>I'm getting this error in Heroku:</p>
  
  <pre><code>PG::Error: ERROR:  column "incomes.filled_at" must appear in the GROUP BY clause 
  or be used in an aggregate function
  </code></pre>
  
  <p>How can I fix this? Thank you.</p>
  
  <p><strong>Executed query:</strong></p>
  
  <pre><code>SELECT SUM("incomes"."lines_price") AS sum_lines_price, date(filled_at)
  AS date_filled_at FROM "incomes"
  HAVING (date(filled_at) &gt; '2012-12-04')
  GROUP BY date(filled_at) ORDER BY filled_at ASC
  </code></pre>
  
  <p><strong>Expected result</strong></p>
  
  <pre><code>[["2012-12-04", SUM_FOR_DATE], ["2012-12-05", SUM_FOR_DATE], ...]
  </code></pre>