rails/rails — Issue #3647: Rails 3.1.1 - AR - .select("COUNT(...)") returns a string with PostgreSQL instead of Integer
Author: bassneck
Created: 2011-11-16 15:13:32+00:00
State: open

I've had this code, that worked as expected on localhost with sqlite3 but not on Heroku.

```ruby
votes = Game.find(1)
.user_votes.select("user_votes.created_at, COUNT(user_votes.id) as count")
.order("user_votes.created_at ASC")
.group("user_votes.created_at")
```
sorry, this is not the best piece of code I've ever written, but it shows the problem.

If you check

```ruby
votes[0].count.is_a?(Integer)
votes[0].count.is_a?(String)
```
with sqlite3 you will get `true`, `false`. But with Postgre, it'll be `false`, `true`.

I thought the problem was in the PG gem, but the auther stated, that it does not type cast records, so I guess it should be something in Rails.

My localhost runs windows 7 x64 with ruby 1.9.2 and rails 3.1.1 using sqlite3
The remote host is heroku cedar.