【发布时间】:2010-04-24 04:04:54
【问题描述】:
出现错误:
ActiveRecord::StatementInvalid (PGError: ERROR: argument of HAVING must be type boolean, not type timestamp without time zone
控制器代码sn-p:
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
【问题讨论】:
-
我建议您复习一下 SQL 的 WHERE、HAVING 和 GROUP BY 子句。 w3schools.com/sql/sql_having.asp。这不是 Rails 问题。
-
是的,它绝对是postgres 比sqlite 更严格,只是想找到一个解决方案....还在学习
标签: ruby-on-rails ruby postgresql heroku