获取错误:

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

控制器代码段:
 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

改变
:having => 'MAX(appointments.start_time)'

:having => ['MAX(appointments.start_time) <= ?', @number_days.days.ago]
现在的错误是:
ActiveRecord::StatementInvalid (PGError: ERROR: column "clients.id" must appear in the GROUP BY clause or be used in an aggregate function

最佳答案

:having子句需要一个计算结果为布尔值的SQL片段MAX(appointments.start_time)计算为时间戳

关于ruby-on-rails - ROR heroku PostGres问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2703177/

10-12 20:17