ruby-on-rails-3 - Rails 3.2 Heroku PG 错误 - 'operator does not exist: integer == integer'

标签 ruby-on-rails-3 postgresql heroku

这在我的开发环境中有效,但是当我尝试通过 Heroku 和 Postgres 运行时,出现此错误。

2012-04-07T21:35:14+00:00 app[web.1]: ActiveRecord::StatementInvalid 
  (PG::Error: ERROR:  operator does not exist: integer == integer 
2012-04-07T21:35:14+00:00 app[web.1]: LINE 1: ...."value") AS avg_id FROM "datapoints"  
  WHERE (habit_id == 1) 
2012-04-07T21:35:14+00:00 app[web.1]: HINT:  No operator matches the given name and argument type(s). 
You might need to add explicit type casts. 
2012-04-07T21:35:14+00:00 app[web.1]: : SELECT  AVG("datapoints"."value") AS avg_id FROM "datapoints 
  WHERE (habit_id == 1)):

下面是我的 Controller 中的代码行:

Datapoint.average(:value, :conditions => ['habit_id == ?', self.habit_id])

我对 Rails 还很陌生,所以这很可能是一个非常简单的错误 - 对我在这里做错了什么有什么想法吗?

最佳答案

只需使用一个等号。

Postgresql(和 SQL 标准)使用单个等号 (=) 进行比较:http://www.postgresql.org/docs/8.0/static/functions-comparison.html

与编程语言不同,SQL 不需要支持使用它进行赋值,除非在更新子句中。因此,它不需要大多数编程语言所需的双等于运算符 (==) 进行比较。

关于ruby-on-rails-3 - Rails 3.2 Heroku PG 错误 - 'operator does not exist: integer == integer',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10059034/

相关文章:

postgresql - 获取两行之间不同的列

ruby - Heroku 内部服务器错误 - ruby​​/Sinatra/Postgresql

django - 最好的 Django syncdb 崩溃调试技术是什么?

javascript - 我在 Safari 5.1.7 中收到错误 "SyntaxError: Expected token ' )' "

ruby-on-rails - 如何让 sidekiq 在 Heroku 上始终保持运行状态?

ruby-on-rails-3 - 在客户端使用 Rails 本地化 I18n

ruby-on-rails - rails 3.1,选择题考试,怎么设计?

ruby-on-rails - 查找所有记录组合

ruby-on-rails - 局部 View 中的实例变量

tsql - 将t-sql(SQL Server)存储过程转换为postgresql(postgresql)的工具