On Wed, Aug 11, 2010 at 22:40, Mohammed Alenazi <vb4...@gmail.com> wrote:

> I have this statement running Ok in my development mode
> �...@users = User.paginate :joins => :properties ,:group =>
> 'users.id', :page => params[:page], :order => 'count(properties.id)
> DESC',:conditions => ['users.id != 1']
>
> when I push my app to Heroku it gives me this error
>
> column "users.email" must appear in the GROUP BY clause or be used in
> an aggregate function
> : SELECT "users".* FROM "users"   INNER JOIN "properties" ON
> properties.user_id = users.id  WHERE (users.id != 1)  GROUP BY
> users.id,users.login,users.name ORDER BY count(properties.id) DESC
> LIMIT 10 OFFSET 0):

I haven't run into this sort of thing, but from my general
SQL/database knowledge, I'd guess that the grouping is causing the
problem.

I assume users.id is unique.  Is that correct?  If so, then grouping
on it (:group => 'users.id') is useless.  Worse than that, though,
it's making the DBMS think that anything else that would probably vary
from row to row, must either be aggregated up to the level of your
chosen group, or chosen as another grouping level.  Otherwise it won't
know what to do with it.  Alternately of course you could omit it,
picking specific attributes rather than users.*.

Rather than aggregating or grouping on the email, it would be easier
and cleaner to just stop grouping by something else (i.e., users.id).
Try that and let us know what happens.

(So why the difference?  My guess would be that MySQL realizes that
grouping on something unique (I'd bet the column is even described to
the database as requiring uniqueness) is a no-op, or maybe goes ahead
and executes the query and then sees that it works out OK, while
PostgreSQL doesn't.)

-Dave

-- 
Specialization is for insects. -RAH  | Have Pun, Will Babble! -me
Programming Blog: http://codosaur.us | Work: http://davearonson.com
Leadership Blog:  http://dare2xl.com | Play: http://davearonson.net
* * * * * WATCH THIS SPACE * * * * * | Ruby: http://mars.groupsite.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to