title: Select lower case column with group by or select lower(column) in Rails 4
body: <p>How to achieve following in rails 4? </p>
  
  <p>Here is my PostgreSQL query and works correctly </p>
  
  <pre><code>SELECT lower(name) as c_name, count(*) as cc FROM categories  GROUP BY c_name  ORDER BY cc desc LIMIT 3
  </code></pre>
  
  <p>Ii gives me following results </p>
  
  <pre><code> "ecommerce solutions";6
   "vmware";6
   "big data analytics";5
  </code></pre>
  
  <p>But when I write same query in Rails 4 as </p>
  
  <pre><code>Category.select("lower(name) as c_name, count(*) as cc").group("c_name").order("cc desc").limit(3) 
  </code></pre>
  
  <p>Above query generates following query which is same as above PostgreSQL query </p>
  
  <pre><code>SELECT lower(name) as c_name, count(*) as cc FROM "categories"  GROUP BY c_name  ORDER BY cc desc LIMIT 3
  </code></pre>
  
  <p>gives following results  </p>
  
  <pre><code>[#&lt;Category id: nil&gt;, #&lt;Category id: nil&gt;, #&lt;Category id: nil&gt;]
  </code></pre>
  
  <p>Why this is happening ? when I cut my query to </p>
  
  <pre><code> Category.select("lower(name)").limit(3)
  </code></pre>
  
  <p>This also does not work, and results into </p>
  
  <pre><code> [#&lt;Category id: nil&gt;, #&lt;Category id: nil&gt;, #&lt;Category id: nil&gt;]
  </code></pre>
  
  <p>I want to do group on <code>lower(name)</code> with count as aggregation, I have many variances of <code>name</code> in <code>Category</code> model </p>
  
  <p>Ex. data set</p>
  
  <pre><code>"Vmware" and "VMware" and "VMWARE" and "vmware" 
  </code></pre>
  
  <p>How can I group on lower(name) in Rails 4? </p>
  
  <p>In simple words, How to write equivalent query of following in Rails 4? </p>
  
  <pre><code>SELECT lower(name) as c_name, count(*) as cc FROM categories  GROUP BY c_name  ORDER BY cc desc LIMIT 3
  </code></pre>