Group() and PostgreSQL strange behavior

Here is a simple request:“user_id”)

And I get:

PGError: ERROR: column “” must appear in the GROUP BY clause
or be used in an aggregate function

If I add to the group by clause, then it asks me to add
another column, then another, then another. Basically I have to list all
columns in the table!

What’s going wrong? From the Rails guide it seemed straightforward.

Thanks for your help


The docs are incomplete. I obviously need to add a count, sum, etc
method for the grouping to make sense.

Actually, as I think about it, you shouldn’t have a Select * in a Group
By? You should select the column(s) you want to aggregate.

Check this out:

I checked my install and received the same results. Looks like a
PostgreSQL syntax thing. I’m new to PostgreSQL and have not looked at
group by SQL syntax.

Off the top of my head, as a (non recommended) work around, you could
insert a .select() with a column list, and it should work. That,
however, is a bad solution for obvious reasons, but might work in a

I tried, and received the same result:

The following worked:

I tried, and received the same result:

The thing is, we group for a reason. So PostgreSQL is expecting that
reason to appear, e.g: count(), sum(), etc.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs