# Find - group - postgres

**URL:** <https://www.ruby-forum.com/t/find-group-postgres/118351>\
**Category:** Rails\
**Created:** [October 25, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/find-group-postgres/118351 "2007-10-25T23:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [October 25, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/find-group-postgres/118351/1 "2007-10-25T23:27:35Z")

</div>

I am not sure that this is entirely a rails question as I am trying to  
run the command in postgres and I am getting the same error…

controller code…

```
  @client_slot_count = ClientSlotsDaily.find(:all,
    :conditions => ["created_at > ? AND created_at < ? AND
     facility_id = ? AND client_id IS NOT NULL",
     starting_date, ending_date, @facility.id],
    :group => 'client_id')

```

error reported is…

PGError: ERROR: column “client\_slots\_dailies.id” must appear in the  
GROUP BY clause or be used in an aggregate function  
: SELECT \* FROM client\_slots\_dailies WHERE (created\_at \> ‘2007-05-01’  
AND created\_at \< ‘2007-07-01’ AND facility\_id = 1 AND client\_id IS NOT  
NULL) GROUP BY client\_id

Which I don’t understand.

create\_table “client\_slots\_dailies”, :force =\> true do |t|  
t.column “name”, :string, :limit =\> 7  
t.column “facility\_id”, :integer  
t.column “placement\_id”, :integer  
t.column “client\_id”, :integer  
t.column “created\_at”, :datetime  
end

I can do ClientSlotsDaily.count etc. but not find as configured.

I don’t want to keep hitting the DB and the group function made sense  
until I tried to use it.

Suggestions?

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [October 26, 2007, 12:00am UTC](https://www.ruby-forum.com/t/find-group-postgres/118351/2 "2007-10-26T00:00:23Z")

</div>

This is not a rails or postgres question. The query you are trying to  
use will not work on any system.  
You want to group data, therefore any fields you are grouping by must  
appear in the output.  
You need to change your thinking and probably use embedded sql not  
depend on the rails generator.
