Find - group - postgres

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,],
    :group => 'client_id')

error reported is…

PGError: ERROR: column “” 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

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.



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.