Gal Ben-Haim
Gal Ben-Haim

Reputation: 17803

Heroku (PG::Error: ERROR: column must appear in the GROUP BY clause or be used in an aggregate function

I'm getting this error on Heroku but not locally (using PostgreSQL on both)..

error is:

ActiveRecord::StatementInvalid (PG::Error: ERROR:  column "posts.content" must appear in the GROUP BY clause or be used in an aggregate function

I suspect it has something to do with this line in my posts model:

scope :with_tags, lambda { |tags| joins(:tags).group('posts.id').where(:tags => { :id => tags.map { |t| t.id } } ).having("COUNT(*) = ?", tags.length) }

why does it happen only on Heroku? how do I fix it ?

Upvotes: 3

Views: 1806

Answers (1)

jordinl
jordinl

Reputation: 5239

As someone pointed out this is a problem with Postgres 9.0 that's been fixed in Postgres 9.1. In Heroku you can use the Heroku Shared PostgreSQL addon instead of the default DB and this should fix the problem.

Upvotes: 1

Related Questions