Search code examples
postgresqlruby-on-rails-3.1production

PostgreSQL -must appear in the GROUP BY clause or be used in an aggregate function


I am getting this error in the pg production mode, but its working fine in sqlite3 development mode.

 ActiveRecord::StatementInvalid in ManagementController#index

PG::Error: ERROR:  column "estates.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "estates".* FROM "estates"  WHERE "estates"."Mgmt" = ...
               ^
: SELECT "estates".* FROM "estates"  WHERE "estates"."Mgmt" = 'Mazzey' GROUP BY user_id

@myestate = Estate.where(:Mgmt => current_user.Company).group(:user_id).all

Solution

  • @myestate1 = Estate.where(:Mgmt => current_user.Company)
    @myestate = @myestate1.select("DISTINCT(user_id)")
    

    this is what I did.