1

getting error:

ActiveRecord::StatementInvalid (PGError: ERROR:  argument of HAVING must be type boolean, not type timestamp without time zone

controller code snippet:

 def inactive
    @number_days = params[:days].to_i || 90
    @clients = Client.find(:all,
      :include => :appointments,
      :conditions => ["clients.user_id = ? AND appointments.start_time <= ?", current_user.id, @number_days.days.ago],
      :group => 'client_id',
      :having => 'MAX(appointments.start_time)'
    )
  end

changed
:having => 'MAX(appointments.start_time)'
to
:having => ['MAX(appointments.start_time) <= ?', @number_days.days.ago]
and now error is:
ActiveRecord::StatementInvalid (PGError: ERROR: column "clients.id" must appear in the GROUP BY clause or be used in an aggregate function

2
  • I suggest you brush up on SQL's WHERE, HAVING and GROUP BY clauses. w3schools.com/sql/sql_having.asp. This is not a Rails issue. Commented Apr 24, 2010 at 15:39
  • yeah, its definitely a postgres is stricter then sqlite thing, just trying to find a solution.... still learning Commented Apr 24, 2010 at 22:31

2 Answers 2

4

The :having clause requires a SQL snippet that evaluates to a boolean. MAX(appointments.start_time) evaluates to a timestamp

Sign up to request clarification or add additional context in comments.

Comments

0

change :group => 'client_id' to :group => 'table_name.client_id'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.